|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.ca.commons.cbutil.CBSecurity
This is a grab bag of useful static functions related to security - mainly doing conversions between PEM and DER.
(nb: PEM = 'Privacy Enhanced Mail' format,
| Field Summary | |
static byte[] |
PEM_BEGIN
Standard header for the base 64 encoded info block of a pem file. |
static byte[] |
PEM_CERT_FOOTER
Standard footer for a pem encoded certificate block |
static byte[] |
PEM_CERT_HEADER
Standard header for a pem encoded certificate block |
static byte[] |
PEM_ENC_KEY_FOOTER
Standard header for a pem encoded encrypted private key block |
static byte[] |
PEM_ENC_KEY_HEADER
Standard header for a pem encoded encrypted private key block |
static byte[] |
PEM_END
Standard footer for the base 64 encoded info block of a pem file. |
static byte[] |
PEM_RSA_KEY_FOOTER
Standard header for a pem encoded RSA private key block |
static byte[] |
PEM_RSA_KEY_HEADER
Standard header for a pem encoded RSA private key block |
| Constructor Summary | |
CBSecurity()
|
|
| Method Summary | |
static byte[] |
convertFromPEM(byte[] pem)
This takes a byte array of PEM (originally rfc 1421-1424, but has drifted a bit) encoded data, such as might be read as raw bytes from a text file, and converts it to 'raw' DER binary data (i.e. a byte array with values from 0x0 to 0xFF). |
static byte[] |
convertFromPEM(byte[] pem,
byte[] header)
This takes a byte array of PEM (originally rfc 1421-1424, but has drifted a bit) encoded data, such as might be read as raw bytes from a text file, and converts it to 'raw' DER binary data (i.e. a byte array with values from 0x0 to 0xFF). |
static byte[] |
convertFromPEM(byte[] pem,
byte[] header,
byte[] footer)
This takes a byte array of PEM (originally rfc 1421-1424, but has drifted a bit) encoded data, such as might be read as raw bytes from a text file, and converts it to 'raw' DER binary data (i.e. a byte array with values from 0x0 to 0xFF). |
static byte[] |
convertFromPEMCertificate(byte[] pem)
This takes a byte array of PEM (originally rfc 1421-1424, but has drifted a bit) encoded data representing an X509 certificate and converts it to 'raw' DER binary data (i.e. a byte array with values from 0x0 to 0xFF). |
protected static byte[] |
convertToPEM(byte[] der,
byte[] header,
byte[] footer)
|
static byte[] |
convertToPEMCertificate(byte[] der)
This takes an array of raw data representing a DER encoded X509 certificate, and base64 encodes it, adding PEM style -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- tags. |
static byte[] |
convertToPEMEncryptedPrivateKey(byte[] der)
This takes an array of raw data representing an Encrypted DER encoded private key (probably pkcs 8), and base64 encodes it, adding PEM style -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- tags. |
static byte[] |
convertToPEMRSAPrivateKey(byte[] der)
This takes an array of raw data representing a DER encoded RSA private key, and base64 encodes it, adding PEM style -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- tags. |
static int |
indexOf(byte[] mainArray,
byte searchByte)
Returns the position that a searchByte first appears in a byte array. |
static int |
indexOf(byte[] mainArray,
byte[] searchSequence)
Tries to match a byte sequence within a larger byte array. |
static int |
indexOf(byte[] mainArray,
byte[] searchSequence,
int fromIndex)
Tries to match a byte sequence within a larger byte array. |
static int |
indexOf(byte[] mainArray,
byte searchByte,
int fromIndex)
Returns the first position, greater than a given index, that a searchByte first appears at within an array. |
static boolean |
isPEM(byte[] test)
A simple check to see if a file is a PEM file, by looking for PEM '------BEGIN...' and PEM '-----END' tags. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final byte[] PEM_BEGIN
public static final byte[] PEM_END
public static final byte[] PEM_CERT_HEADER
public static final byte[] PEM_CERT_FOOTER
public static final byte[] PEM_ENC_KEY_HEADER
public static final byte[] PEM_ENC_KEY_FOOTER
public static final byte[] PEM_RSA_KEY_HEADER
public static final byte[] PEM_RSA_KEY_FOOTER
| Constructor Detail |
public CBSecurity()
| Method Detail |
public static int indexOf(byte[] mainArray,
byte searchByte)
mainArray - the byte array to search withinsearchByte - the byte to look for
public static int indexOf(byte[] mainArray,
byte searchByte,
int fromIndex)
mainArray - the byte array to search withinsearchByte - the byte to look for
public static int indexOf(byte[] mainArray,
byte[] searchSequence)
Tries to match a byte sequence within a larger byte array.
Students of Sun's java.lang.String class may recognise some of this code :-).
mainArray - the base array to search within.searchSequence - the short sequence to find the position of
within the main array.
public static int indexOf(byte[] mainArray,
byte[] searchSequence,
int fromIndex)
Tries to match a byte sequence within a larger byte array.
Students of Sun's java.lang.String class may recognise some of this code :-).
mainArray - the base array to search within.searchSequence - the short sequence to find the position of
within the main array.fromIndex - the position to start searching from.
public static boolean isPEM(byte[] test)
public static byte[] convertFromPEM(byte[] pem)
pem - the pem data to convert
public static byte[] convertFromPEM(byte[] pem,
byte[] header)
This takes a byte array of PEM (originally rfc 1421-1424, but has drifted a bit) encoded data, such as might be read as raw bytes from a text file, and converts it to 'raw' DER binary data (i.e. a byte array with values from 0x0 to 0xFF).
In addition, this method allows the start of the PEM header tag to be explicitly specified. This is useful when a single file contains multiple data blocks (e.g. a cert *and* a private key). Only the beginning of the stard header needs to be specified; e.g. '-----BEGIN RSA PRIVATE' is sufficient, the full header is not required. (The footer is assumed to be the first block starting with '-----END...')
pem - the pem data to convert
public static byte[] convertFromPEMCertificate(byte[] pem)
This takes a byte array of PEM (originally rfc 1421-1424, but has drifted a bit) encoded data representing an X509 certificate and converts it to 'raw' DER binary data (i.e. a byte array with values from 0x0 to 0xFF).
pem - the pem data containing a certificate to convert
public static byte[] convertFromPEM(byte[] pem,
byte[] header,
byte[] footer)
This takes a byte array of PEM (originally rfc 1421-1424, but has drifted a bit) encoded data, such as might be read as raw bytes from a text file, and converts it to 'raw' DER binary data (i.e. a byte array with values from 0x0 to 0xFF).
In addition, this method allows the start of the PEM header and footer tag to be explicitly specified. This is useful when a single file contains multiple data blocks (e.g. a cert *and* a private key). Only the beginning of the headers needs to be specified; e.g. '-----BEGIN RSA PRIVATE' is sufficient, the full header/footer is not required.
pem - the pem data to convert
public static byte[] convertToPEMCertificate(byte[] der)
der - the DER encoded datapublic static byte[] convertToPEMRSAPrivateKey(byte[] der)
der - the DER encoded datapublic static byte[] convertToPEMEncryptedPrivateKey(byte[] der)
der - the DER encoded data
protected static byte[] convertToPEM(byte[] der,
byte[] header,
byte[] footer)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||