Package org.cryptacular.util
Class PemUtil
java.lang.Object
org.cryptacular.util.PemUtil
Utility class with helper methods for common PEM encoding operations.
- Author:
- Middleware Services
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Decryption infor tag for PEM-encoded private key in OpenSSL format.static final String
PEM encoding footer start string.static final String
PEM encoding header start string.static final int
Line length.static final String
Procedure type tag for PEM-encoded private key in OpenSSL format. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
decode
(byte[] pem) Decodes a PEM-encoded cryptographic object into the raw bytes of its ASN.1 encoding.static byte[]
Decodes one or more PEM-encoded cryptographic objects into the raw bytes of their ASN.1 encoding.static boolean
isBase64Char
(byte b) Determines whether the given byte represents an ASCII character in the character set for base64 encoding.static boolean
isPem
(byte[] data) Determines whether the data in the given byte array is base64-encoded data of PEM encoding.
-
Field Details
-
LINE_LENGTH
public static final int LINE_LENGTHLine length.- See Also:
-
HEADER_BEGIN
PEM encoding header start string.- See Also:
-
FOOTER_END
PEM encoding footer start string.- See Also:
-
PROC_TYPE
Procedure type tag for PEM-encoded private key in OpenSSL format.- See Also:
-
DEK_INFO
Decryption infor tag for PEM-encoded private key in OpenSSL format.- See Also:
-
-
Method Details
-
isPem
public static boolean isPem(byte[] data) Determines whether the data in the given byte array is base64-encoded data of PEM encoding. The determination is made using as little data from the given array as necessary to make a reasonable determination about encoding.- Parameters:
data
- Data to test for PEM encoding- Returns:
- True if data appears to be PEM encoded, false otherwise.
-
isBase64Char
public static boolean isBase64Char(byte b) Determines whether the given byte represents an ASCII character in the character set for base64 encoding.- Parameters:
b
- Byte to test.- Returns:
- True if the byte represents an ASCII character in the set of valid characters for base64 encoding, false otherwise. The padding character '=' is not considered valid since it may only appear at the end of a base64 encoded value.
-
decode
public static byte[] decode(byte[] pem) Decodes a PEM-encoded cryptographic object into the raw bytes of its ASN.1 encoding. Header/footer data and metadata info, e.g. Proc-Type, are ignored.- Parameters:
pem
- Bytes of PEM-encoded data to decode.- Returns:
- ASN.1 encoded bytes.
-
decode
Decodes one or more PEM-encoded cryptographic objects into the raw bytes of their ASN.1 encoding. All header and metadata, e.g. Proc-Type, are ignored. If multiple cryptographic objects are represented, the decoded bytes of each object are concatenated together and returned.- Parameters:
pem
- PEM-encoded data to decode.- Returns:
- ASN.1 encoded bytes.
-