|
Oracle Fusion Middleware Crypto Java API Reference for Oracle Security Developer Tools 11g Release 1 (11.1.1) E10668-05 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
oracle.security.crypto.util.Utils
public class Utils
A set of utility functions. All conversions use network (big-endian) order.
Constructor Summary | |
---|---|
Utils() |
Method Summary | |
---|---|
static boolean |
areEqual(byte[] a, byte[] b) Compares two byte arrays for equality. |
static boolean |
areEqual(byte[] a, int aOff, byte[] b, int bOff, int len) Compares two byte arrays for equality from the given offsets over the given length. |
static void |
bytesToChars(byte[] b, char[] c) |
static void |
bytesToLongs(byte[] b, int bOff, long[] l, int lOff, int lLen) Converts an array of bytes into an array of longs. |
static short |
bytesToShort(int b1, int b2) Constructs a short value from two bytes, assuming a big-endian representation. |
static void |
bytesToShorts(byte[] b, short[] s) Converts an array of bytes into an array of shorts. |
static java.lang.String |
bytesToUnicode(byte[] b) |
static int |
bytesToWord(int b1, int b2, int b3, int b4) Constructs an int value from four bytes, assuming a big-endian representation. |
static void |
bytesToWords(byte[] b, int[] w) Converts an array of bytes into an array of ints. |
static void |
bytesToWords(byte[] b, int bOff, int[] w, int wOff, int wLen) Converts an array of bytes into an array of ints. |
static void |
charsToBytes(char[] c, byte[] b) Converts an array of 16-bit chararacters into an array of bytes. |
static java.util.Date |
daysFrom(java.util.Date d, int days) |
static java.util.Date |
daysFromNow(int days) |
static void |
dumpHex(java.io.PrintStream out, byte[] data) Dumps a two-column hex/printable char mapping of a bytestream to the specified output stream, like "hexdump" programs of yore. |
static java.lang.String |
formatDate(java.util.Date d) |
static java.lang.String |
formatDate(java.util.Date d, boolean longYear) |
static byte[] |
fromBase64(java.lang.String s) Returns the decoded form of the given Base-64 encoded string. |
static byte[] |
fromHexString(java.lang.String s) Converts the specified hex string into an array of bytes. |
static java.lang.String |
fromURLEncoded(java.lang.String s) |
static java.lang.String |
fromUTF8(byte[] bytes) Creates a string by decoding the given UTF-8 representation. |
static int |
hashBytes(Streamable o) |
static int |
input24bit(java.io.InputStream in) Reads three bytes from the given input stream and uses them to construct an int value, assuming a big-endian representation. |
static java.math.BigInteger |
inputBignum(int nBytes, java.io.InputStream is) Input an unsigned integer. |
static byte |
inputByte(java.io.InputStream is) Reads one byte from the given input stream. |
static byte[] |
inputByteArray(byte[] buf, java.io.InputStream is) Fills up the specified byte array by reading from the input stream, then returns that byte array. |
static void |
inputByteArray(byte[] buf, int off, int len, java.io.InputStream is) Fills up the specified byte array by reading from the input stream, then returns that byte array. |
static byte[] |
inputBytes(java.io.InputStream is, int len) Reads the indicated number of bytes from the given input stream. |
static short |
inputShort(java.io.InputStream in) Reads two bytes from the given input stream and uses them to construct a short value, assuming a big-endian representation. |
static int |
inputWord(java.io.InputStream in) Reads four bytes from the given input stream and uses them to construct an int value, assuming a big-endian representation. |
static int |
length(oracle.security.crypto.core.math.BigInt val) Returns the number of bytes needed to represent a given nonnegative integer, not including the sign bit. |
static int |
length(java.math.BigInteger val) Returns the number of bytes needed to represent a given nonnegative integer, not including the sign bit. |
static void |
longsToBytes(long[] l, byte[] b) Converts an array of long values into an array of bytes. |
static void |
longsToBytes(long[] l, int lOff, byte[] b, int bOff, int lLen) Converts an array of long values into an array of bytes. |
static byte[] |
longToBytes(long l) Returns the big endian representation of the given long value, as an array of eight bytes. |
static java.util.Date |
minutesFrom(java.util.Date d, int minutes) |
static void |
output(java.math.BigInteger n, java.io.OutputStream out) Outputs the big endian representation of the given big integer to the specified output stream. |
static void |
output(int w, java.io.OutputStream out) Outputs the big endian representation of the given int value to the specified output stream. |
static void |
output(long l, java.io.OutputStream out) Outputs the big endian representation of the given long value to the specified output stream. |
static void |
output(short s, java.io.OutputStream out) Outputs the big endian representation of the given short value to the specified output stream. |
static void |
output24bit(int w, java.io.OutputStream out) Outputs the big endian representation of least significant 24 bits of the given int value to the specified output stream. |
static void |
outputBignum(java.math.BigInteger val, java.io.OutputStream os) Output an unsigned integer. |
static void |
outputLong(long l, java.io.OutputStream out) Outputs the big endian representation of the given long value to the specified output stream. |
static void |
outputShort(int s, java.io.OutputStream out) Outputs the big endian representation of the given short value to the specified output stream. |
static void |
outputString(java.lang.String s, java.io.OutputStream os) Deprecated. |
static void |
outputWord(int w, java.io.OutputStream out) Outputs the big endian representation of the given int value to the specified output stream. |
static java.util.Date |
parseDate(java.lang.String s) |
static java.util.Date |
parseDate(java.lang.String s, boolean longYear) |
static java.lang.String |
plural(int n, java.lang.String noun) |
static int |
rotl(int x, int s) Performs a left bitwise rotation. |
static short |
rotlShort(int x, int s) Performs a left bitwise rotation. |
static int |
rotr(int x, int s) Performs a right bitwise rotation. |
static short |
rotrShort(int x, int s) Performs a right bitwise rotation. |
static void |
setArray(byte[] arr, byte b) Fills the specified byte array with a given value. |
static void |
setArray(byte[] arr, int off, int len, byte b) |
static void |
setArray(int[] arr, int w) Fills the specified int array with a given value. |
static void |
setArray(short[] arr, short s) Fills the specified short array with a given value. |
static void |
shortsToBytes(short[] s, byte[] b) Converts an array of short values into an array of bytes. |
static byte[] |
shortToBytes(short s) Returns the big endian representation of the given short value, as an array of two bytes. |
static java.lang.String |
stripEOL(java.lang.String s) Returns a copy of the given string with all CR and LF characters removed. |
static java.lang.String |
toBase64(byte[] data) Returns the Base-64 encoding of the given byte array. |
static java.lang.String |
toBase64(byte[] data, boolean insertSeparators) Returns the Base-64 encoding of the given byte array. |
static java.lang.String |
toBase64(byte[] data, java.lang.String lineSeparator) |
static byte[] |
toByteArray(oracle.security.crypto.core.math.BigInt val) Convert an unsigned integer to a big-endian unsigned representation. |
static void |
toByteArray(oracle.security.crypto.core.math.BigInt val, byte[] buf, int off, int len) Convert an unsigned integer to a big-endian unsigned representation of fixed length. |
static byte[] |
toByteArray(java.math.BigInteger val) Convert an unsigned integer to a big-endian unsigned representation. |
static void |
toByteArray(java.math.BigInteger val, byte[] buf, int off, int len) Convert an unsigned integer to a big-endian unsigned representation of fixed length. |
static byte[] |
toBytes(java.io.InputStream is) Returns characters from the given stream until end-of-stream is reached, and stores the read characters into a byte array. |
static byte[] |
toBytes(Streamable o) Stores the output of a Streamable object into a byte array. |
static java.lang.String |
toHexString(byte[] b) Returns the hex representation of the specified array of bytes. |
static java.lang.String |
toHexString(byte[] b, int off, int len) Returns the hex representation of the specified sequence of bytes. |
static java.io.InputStream |
toStream(Streamable o) |
static java.lang.String |
toString(java.util.List<?> v) Produces a string representation of the input Vector in a format consistent with the rest of the oracle.security.crypto. classes. |
static java.lang.String |
toString(java.util.Vector<?> v) Deprecated. use toString(List) instead |
static java.lang.String |
toURLEncoded(java.lang.String s) |
static byte[] |
toUTF8(java.lang.String s) Returns the UTF-8 representation of the given string. |
static byte[] |
unicodeToBytes(java.lang.String s) |
static void |
wordsToBytes(int[] w, byte[] b) Converts an array of int values into an array of bytes. |
static void |
wordsToBytes(int[] w, int wOff, byte[] b, int bOff, int wLen) Converts an array of int values into an array of bytes. |
static byte[] |
wordToBytes(int w) Returns the big endian representation of the given int value, as an array of four bytes. |
static byte[] |
xor(byte[] a, byte[] b) Utility function that performs a bitwise exclusive-or of two byte arrays. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Utils()
Method Detail |
---|
public static short rotlShort(int x, int s)
x
- value to rotates
- number of bits to rotatepublic static short rotrShort(int x, int s)
x
- value to rotates
- number of bits to rotatepublic static void setArray(byte[] arr, byte b)
public static void setArray(short[] arr, short s)
public static void setArray(int[] arr, int w)
public static void setArray(byte[] arr, int off, int len, byte b)
public static int rotl(int x, int s)
x
- value to rotates
- number of bits to rotatepublic static int rotr(int x, int s)
x
- value to rotates
- number of bits to rotatepublic static int bytesToWord(int b1, int b2, int b3, int b4)
b1
- The most significant 8 bits.b2
- The next 8 bits.b3
- The next 8 bits.b4
- The least significant 8 bits.public static short bytesToShort(int b1, int b2)
b1
- The most significant 8 bits.b2
- The least significant 8 bits.public static void bytesToWords(byte[] b, int bOff, int[] w, int wOff, int wLen)
public static void bytesToWords(byte[] b, int[] w)
public static void bytesToLongs(byte[] b, int bOff, long[] l, int lOff, int lLen)
public static void bytesToShorts(byte[] b, short[] s)
public static void bytesToChars(byte[] b, char[] c)
public static byte[] longToBytes(long l)
public static byte[] wordToBytes(int w)
public static byte[] shortToBytes(short s)
public static void longsToBytes(long[] l, byte[] b)
public static void longsToBytes(long[] l, int lOff, byte[] b, int bOff, int lLen)
public static void wordsToBytes(int[] w, int wOff, byte[] b, int bOff, int wLen)
public static void wordsToBytes(int[] w, byte[] b)
public static void shortsToBytes(short[] s, byte[] b)
public static void charsToBytes(char[] c, byte[] b)
public static byte[] unicodeToBytes(java.lang.String s)
public static java.lang.String bytesToUnicode(byte[] b)
public static byte[] toByteArray(java.math.BigInteger val)
public static void toByteArray(java.math.BigInteger val, byte[] buf, int off, int len) throws java.lang.ArithmeticException
java.lang.ArithmeticException
public static int length(java.math.BigInteger val)
val
- the integer value, which must be nonnegativepublic static byte[] toByteArray(oracle.security.crypto.core.math.BigInt val)
public static void toByteArray(oracle.security.crypto.core.math.BigInt val, byte[] buf, int off, int len) throws java.lang.ArithmeticException
java.lang.ArithmeticException
public static int length(oracle.security.crypto.core.math.BigInt val)
val
- the integer value, which must be nonnegativepublic static boolean areEqual(byte[] a, byte[] b)
public static boolean areEqual(byte[] a, int aOff, byte[] b, int bOff, int len)
public static java.lang.String plural(int n, java.lang.String noun)
public static java.lang.String fromUTF8(byte[] bytes)
java.io.DataOutputStream
.InvalidFormatException
- if the encoding is malformed. Note that this is a runtime exception. If the encoding consists only of ASCII values (0..127), this exception cannot occur.public static byte[] toUTF8(java.lang.String s)
java.io.DataInputStream
and java.io.DataOutputStream
.public static int inputWord(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public static int input24bit(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public static short inputShort(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public static byte inputByte(java.io.InputStream is) throws java.io.IOException
java.io.IOException
public static byte[] inputBytes(java.io.InputStream is, int len) throws java.io.IOException
java.io.IOException
public static byte[] inputByteArray(byte[] buf, java.io.InputStream is) throws java.io.IOException
java.io.IOException
public static void inputByteArray(byte[] buf, int off, int len, java.io.InputStream is) throws java.io.IOException
java.io.IOException
public static byte[] toBytes(java.io.InputStream is) throws java.io.IOException
is
- the input streamjava.io.IOException
public static void output(long l, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static void output(int w, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static void output(short s, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static void output(java.math.BigInteger n, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static void outputLong(long l, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static void outputWord(int w, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static void output24bit(int w, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static void outputShort(int s, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static void outputBignum(java.math.BigInteger val, java.io.OutputStream os) throws java.io.IOException
java.io.IOException
public static java.math.BigInteger inputBignum(int nBytes, java.io.InputStream is) throws java.io.IOException
nBytes
- the length of the inputjava.io.IOException
public static void outputString(java.lang.String s, java.io.OutputStream os) throws java.io.IOException
java.io.IOException
public static void dumpHex(java.io.PrintStream out, byte[] data)
public static java.lang.String toHexString(byte[] b, int off, int len)
b
- the byte arrayoff
- where to startlen
- number of bytespublic static java.lang.String toHexString(byte[] b)
public static byte[] fromHexString(java.lang.String s)
java.lang.NumberFormatException
- if the string is not correctly formed (i.e., contains non-hexadecimal digits or has length not evenly divisible by 2).public static java.lang.String toBase64(byte[] data)
Returns the Base-64 encoding of the given byte array. The result will contain line separators.
Base-64 (a.k.a. PEM printable encoding) is described in RFC 1421.
data
- The data to be encoded.public static java.lang.String toBase64(byte[] data, boolean insertSeparators)
Returns the Base-64 encoding of the given byte array. A flag is used to indicate whether line separators are to be inserted; if so, then the value of the system property line.separator
is used for this purpose.
Base-64 (a.k.a. PEM printable encoding) is described in RFC 1421.
data
- The data to be encoded.insertSeparators
- If true
, then the result will contain line separators.public static java.lang.String toBase64(byte[] data, java.lang.String lineSeparator)
public static byte[] fromBase64(java.lang.String s)
Returns the decoded form of the given Base-64 encoded string.
Line breaks will be ignored, provided they are of the form CR, LF, or CR LF, and do not occur twice in a row or in the middle of a four-character block.
Base-64 (a.k.a. PEM printable encoding) is described in RFC 1421.
s
- The string to be decoded.public static java.lang.String stripEOL(java.lang.String s)
public static java.lang.String fromURLEncoded(java.lang.String s)
public static java.lang.String toURLEncoded(java.lang.String s)
public static java.util.Date parseDate(java.lang.String s)
public static java.util.Date parseDate(java.lang.String s, boolean longYear)
public static java.lang.String formatDate(java.util.Date d)
public static java.lang.String formatDate(java.util.Date d, boolean longYear)
public static java.util.Date daysFrom(java.util.Date d, int days)
public static java.util.Date daysFromNow(int days)
public static java.util.Date minutesFrom(java.util.Date d, int minutes)
public static byte[] toBytes(Streamable o)
StreamableOutputException
- If an I/O error unexpectedly occurs.public static java.io.InputStream toStream(Streamable o)
public static int hashBytes(Streamable o)
public static java.lang.String toString(java.util.Vector<?> v)
toString(List)
insteadVector
in a format consistent with the rest of the oracle.security.crypto.
classes.public static java.lang.String toString(java.util.List<?> v)
Vector
in a format consistent with the rest of the oracle.security.crypto.
classes.public static byte[] xor(byte[] a, byte[] b)
If the byte arrays are of different length, the shorter one is xor'd into the trailing bytes of the larger one and the larger one's leading bytes are left unchanged.
If byte array a or byte array b are null, a NullPointerException will be thrown.
a
- The first byte array to be xor'd.b
- The second byte array to be xor'd.a xor b
. It will be the size of the larger of the two parameter arrays.
|
Oracle Fusion Middleware Crypto Java API Reference for Oracle Security Developer Tools 11g Release 1 (11.1.1) E10668-05 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |