public class DERDecoderUtils extends Object
It maintains a "current position" in the array that advances with each operation, providing a simple means to handle the type-length-value encoding of DER. For example
decoder.expect(TYPE); int length = decoder.getLength(); byte[] value = decoder.getBytes(len);
| Modifier and Type | Field and Description |
|---|---|
static byte |
TYPE_BIT_STRING
DER type identifier for a bit string value
|
static byte |
TYPE_OBJECT_IDENTIFIER
DER type identifier for ASN.1 "OBJECT IDENTIFIER" value.
|
static byte |
TYPE_OCTET_STRING
DER type identifier for a octet string value
|
static byte |
TYPE_SEQUENCE
DER type identifier for a sequence value
|
| Constructor and Description |
|---|
DERDecoderUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
decodeOID(byte[] oidBytes)
The first two nodes of the OID are encoded onto a single byte.
|
static byte[] |
getAlgorithmIdBytes(InputStream derEncodedIS)
Simple method parses an ASN.1 encoded byte array.
|
static String |
getAlgorithmIdFromPublicKey(PublicKey publicKey)
The method extracts the algorithm OID from the public key and returns it as "dot encoded" OID string.
|
static int |
readLength(InputStream derEncodedIs)
Get the DER length at the current position.
|
static byte[] |
readObjectIdentifier(InputStream derEncodedIS)
Read the next object identifier from the given DER-encoded input stream.
|
public static final byte TYPE_BIT_STRING
public static final byte TYPE_OCTET_STRING
public static final byte TYPE_SEQUENCE
public static final byte TYPE_OBJECT_IDENTIFIER
public static byte[] getAlgorithmIdBytes(InputStream derEncodedIS) throws DERDecodingException, IOException
PublicKeyInfo ::= SEQUENCE {
algorithm AlgorithmIdentifier,
PublicKey BIT STRING
}
Where AlgorithmIdentifier is formatted as:
AlgorithmIdentifier ::= SEQUENCE {
algorithm OBJECT IDENTIFIER,
parameters ANY DEFINED BY algorithm OPTIONAL
}
derEncodedIS - the DER-encoded input stream to decode.DERDecodingException - in case of decoding error or if given InputStream is null or empty.IOException - if an I/O error occurs.public static byte[] readObjectIdentifier(InputStream derEncodedIS) throws DERDecodingException
derEncodedIS - the DER-encoded input stream to decode.DERDecodingException - if parse error occurs.public static String getAlgorithmIdFromPublicKey(PublicKey publicKey) throws DERDecodingException
publicKey - the public key for which method returns algorithm ID.DERDecodingException - if the algorithm ID cannot be determined.public static int readLength(InputStream derEncodedIs) throws DERDecodingException, IOException
DER length is encoded as
DERDecodingException - if the current position is at the end of the array or there is
an incomplete length specification.IOException - if an I/O error occurs.public static String decodeOID(byte[] oidBytes)
oidBytes - the byte array containing the OIDCopyright © 2000–2025 The Apache Software Foundation. All rights reserved.