|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--iaik.utils.Util
This class provides some general useful methods.
| Method Summary | |
static X509Certificate[] |
arrangeCertificateChain(X509Certificate[] certArray,
boolean topdown)
Tries to construct a certificate chain from an array of certificates. |
static byte[] |
Base64Decode(byte[] in)
Decodes a Base64 encoded byte array. |
static byte[] |
Base64Encode(byte[] in)
Encodes a binary byte array into Base64. |
static int[] |
bubbleSort(int[] a)
Sort the given array of ints in ascending order and return it. |
static long[] |
bubbleSort(long[] a)
Sort the given array of longs in ascending order and return it. |
static void |
compareTables(java.lang.String text,
int[] T0,
int[] T1)
|
static X509Certificate[] |
convertCertificateChain(Certificate[] certificateChain)
This method converts an array of Certificates into an array of X509Certificates. |
static byte[] |
convertEndian32(byte[] in)
Convert between little and big endian 32 bit formats. |
static byte[] |
decodeByteArray(java.lang.String st)
Decode base64 encoded data from the given string and return it as a byte array. |
static int[] |
decodeIntArray(java.lang.String st)
Decode base64 encoded data from the given string and return it as an int array. |
static java.lang.String |
encodeByteArray(byte[] b)
Encode an byte array in base64 and return it as a string. |
static java.lang.String |
encodeIntArray(int[] a)
Encode an int array in base64 and return it as a string. |
static void |
fillArray(byte[] array,
java.io.InputStream is)
This method tries to fill the given array with data read from the InputStream. |
static java.util.Vector |
getVector(java.lang.Object[] array)
This method converts an array to a Vector. |
static boolean |
loadClass(java.lang.String name,
boolean createInstance)
Tries to dynamically load a class. |
static void |
printTable(java.lang.String text,
byte[] table)
|
static void |
printTable(java.lang.String text,
int[] table)
|
static byte[] |
readFile(java.lang.String fileName)
Reads the content of a file into a byte array. |
static byte[] |
readStream(java.io.InputStream in)
Read the contents of the stream into a byte array. |
static byte[] |
resizeArray(byte[] array,
int len)
Resizes a byte array to the specified length. |
static java.lang.Object[] |
resizeArray(java.lang.Object[] array,
int len)
Resizes a byte array to the specified length. |
static void |
saveToFile(byte[] array,
java.lang.String fileName)
Saves the content of the given byte array to a file. |
static java.lang.Object[] |
toArray(java.util.Vector aVector)
This method converts a Vector to an array. |
static java.lang.Object[] |
toArray(java.util.Vector aVector,
java.lang.Class cls)
This method converts a Vector to an array. |
static byte[] |
toASCIIBytes(java.lang.String s)
Convert the String to a byte[] in the ASCII encoding. |
static java.lang.String |
toASCIIString(byte[] bytes)
Convert the bytes to a String using the ASCII encoding. |
static java.lang.String |
toASCIIString(byte[] bytes,
int ofs,
int cnt)
Convert the bytes to a String using the ASCII encoding. |
static int |
toByte(char c,
int radix)
Convert the given char to an int. |
static byte[] |
toByteArray(java.lang.String s)
Convert the given string with hex values to a byte array. |
static java.lang.String |
toPemString(Certificate cert)
Convert the given Certificate to a PEM style base64 encoded string. |
static java.lang.String |
toPemString(PrivateKey privKey)
Convert the given private key to a PEM style base64 encoded string. |
static java.lang.String |
toString(byte b)
Converts a byte into a hexadecimal string. |
static java.lang.String |
toString(byte[] byteArray)
Converts a byte array into a hexadecimal string of the format: 01:23:34:56... |
static java.lang.String |
toString(byte[] byteArray,
int off,
int len)
Converts the specified subsequence of the given byte array into a hexadecimal string of the format: 01:23:34:56... |
static java.lang.String |
toString(int i)
Converts an int into a hexadecimal string of the format: 01:23:34:56... |
static java.lang.String |
toString(long l)
Converts an int into a hexadecimal string of the format: 01:23:34:56... |
static void |
waitKey()
Wait for the user to press the return key on System.in. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Method Detail |
public static boolean loadClass(java.lang.String name,
boolean createInstance)
The class to be loaded has to be specified by its name (including the whole package hierachy), e.g.:
Util.loadClass("iaik.test.testdemo.Test1", true);
For actually creating a new instance of the requested class - some
implementations of the Java-VM only execute the static part of a class
if a new instance is created - set the createInstance
parameter to true.name - the name of the class to load (e.g. "iaik.Test")createInstance - if set to true a new instance of the
specified class is created;true, if the class has been loaded successfully and a new
instance has been created (if desired); false
otherwise
public static byte[] readFile(java.lang.String fileName)
throws java.io.IOException
fileName - the name of the file to read
public static byte[] readStream(java.io.InputStream in)
throws java.io.IOException
public static void saveToFile(byte[] array,
java.lang.String fileName)
throws java.io.IOException
array - the byte array supplying the data to be written to the filefileName - the name of the file to which the data shall be writtenpublic static java.lang.String toString(byte b)
For instance:
byte b = ...; System.out.println(Util.toString(b));
b - the byte to convert
public static java.lang.String toString(byte[] byteArray,
int off,
int len)
Starting at off, len bytes will be converted and
returned as hexadecimal string, e.g.:
byte[] arr = ...; System.out.println(Util.toString(arr, 0, 3));
byteArray - the byte array containing the dataoff - the offset indicating the start position within the given byte array; the
following len bytes will be converted into a hexadecimal stringlen - how many bytes shall be writtenpublic static java.lang.String toString(byte[] byteArray)
For instance:
byte[] arr = ...; System.out.println(Util.toString(arr));
byteArray - the byte array containing the datapublic static java.lang.String toString(int i)
For instance:
int i = ...; System.out.println(Util.toString(i));
i - the int to convertpublic static java.lang.String toString(long l)
public static byte[] Base64Encode(byte[] in)
Base64 is the encoding format used by Multipurpose Internet Mail Extension (Mime) for transmitting non-text material over text-only communications channels. Base64 is based on a 65-character subset of US-ASCII, enabling 6 bits to be represented per printable character (see RFC 1521).
This method may be used for Base64 encoding some already DER encoded ASN1 object to get the PEM (Base64 DER) encoding, e.g.:
ASN1 asn1 = ...; //DER encode the ASN1 data structure just created: byte[] der_array = asn1.toByteArray(); //Base64 encode the DER encoded byte array just created to get the //PEM encoding: byte[] pem_array = Util.Base64Encode(der_array);
in - the binary data to be Base64 encoded
public static byte[] Base64Decode(byte[] in)
throws Base64Exception
Base64 is the encoding format used by Multipurpose Internet Mail Extension (Mime) for transmitting non-text material over text-only communications channels. Base64 is based on a 65-character subset of US-ASCII, enabling 6 bits to be represented per printable character (see RFC 1521).
For instance:
byte[] data = ...; byte[] encoded_data = Util.Base64Encode(data); byte[] decoded_data = Util.Base64Decode(encoded_data);
in - the Base64 encoded data to be decoded
public static byte[] resizeArray(byte[] array,
int len)
If len is smaller than the array size some bytes are lost.
array - the array to resizelen - the new length of the array
public static java.lang.Object[] resizeArray(java.lang.Object[] array,
int len)
If len is smaller than the array size some bytes are lost.
array - the array to resizelen - the new length of the array
public static void fillArray(byte[] array,
java.io.InputStream is)
throws java.io.IOException
array - the array to fillis - the InputStream to read frompublic static java.util.Vector getVector(java.lang.Object[] array)
array - the array to convertpublic static java.lang.Object[] toArray(java.util.Vector aVector)
aVector - the Vector to convert
public static java.lang.Object[] toArray(java.util.Vector aVector,
java.lang.Class cls)
AType[] test = (AType[])Util.toArray(aVector, AType.class);Without using the specified class a ClassCastException would occur.
aVector - the Vector to convertcls - specifies the type of the elementspublic static void waitKey()
public static int toByte(char c,
int radix)
public static byte[] toByteArray(java.lang.String s)
public static byte[] decodeByteArray(java.lang.String st)
throws java.lang.RuntimeException
public static java.lang.String encodeByteArray(byte[] b)
public static int[] decodeIntArray(java.lang.String st)
throws java.lang.RuntimeException
public static java.lang.String encodeIntArray(int[] a)
public static java.lang.String toPemString(Certificate cert)
-----BEGIN CERTIFICATE----- BASE64DATA -----END CERTIFICATE-----All lines will be terminated by '\n'. In case of a CertificateEncodingException null will be returned (should never occur with the IAIK JCE).
public static java.lang.String toPemString(PrivateKey privKey)
-----BEGIN RSA PRIVATE KEY----- BASE64DATA -----END RSA PRIVATE KEY-----All lines will be terminated by '\n'.
public static long[] bubbleSort(long[] a)
public static int[] bubbleSort(int[] a)
public static X509Certificate[] convertCertificateChain(Certificate[] certificateChain)
throws CertificateException
certificateChain - the array of certificates to convert
public static X509Certificate[] arrangeCertificateChain(X509Certificate[] certArray,
boolean topdown)
null is returned. This method builds the chain by checking
issuer and subject and testing the signatures.certArray - an array of certificatestopdown - if true the certificate chain will be returned with the
top-CA-certificate at index 0, otherwise with the
top-CA-certificate at the array's last index.null if the array did not
contain a certificate chain.public static byte[] convertEndian32(byte[] in)
public static java.lang.String toASCIIString(byte[] bytes,
int ofs,
int cnt)
public static java.lang.String toASCIIString(byte[] bytes)
public static byte[] toASCIIBytes(java.lang.String s)
public static void compareTables(java.lang.String text,
int[] T0,
int[] T1)
public static void printTable(java.lang.String text,
byte[] table)
public static void printTable(java.lang.String text,
int[] table)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||