Class DERParser

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class DERParser
    extends java.io.FilterInputStream
    A bare minimum DER parser - just enough to be able to decode signatures and private keys
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] lenBytes  
      static int MAX_DER_VALUE_LENGTH
      Maximum size of data allowed by readLength() - it is a bit arbitrary since one can encode 32-bit length data, but it is good enough for the keys
      • Fields inherited from class java.io.FilterInputStream

        in
    • Constructor Summary

      Constructors 
      Constructor Description
      DERParser​(byte... bytes)  
      DERParser​(byte[] bytes, int offset, int len)  
      DERParser​(java.io.InputStream s)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.math.BigInteger readBigInteger()  
      int readLength()
      Decode the length of the field.
      ASN1Object readObject()  
      • Methods inherited from class java.io.FilterInputStream

        available, close, mark, markSupported, read, read, read, reset, skip
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MAX_DER_VALUE_LENGTH

        public static final int MAX_DER_VALUE_LENGTH
        Maximum size of data allowed by readLength() - it is a bit arbitrary since one can encode 32-bit length data, but it is good enough for the keys
        See Also:
        Constant Field Values
      • lenBytes

        private final byte[] lenBytes
    • Constructor Detail

      • DERParser

        public DERParser​(byte... bytes)
      • DERParser

        public DERParser​(byte[] bytes,
                         int offset,
                         int len)
      • DERParser

        public DERParser​(java.io.InputStream s)
    • Method Detail

      • readLength

        public int readLength()
                       throws java.io.IOException
        Decode the length of the field. Can only support length encoding up to 4 octets. In BER/DER encoding, length can be encoded in 2 forms:
        • Short form - One octet. Bit 8 has value "0" and bits 7-1 give the length.

        • Long form - Two to 127 octets (only 4 is supported here). Bit 8 of first octet has value "1" and bits 7-1 give the number of additional length octets. Second and following octets give the length, base 256, most significant digit first.

        Returns:
        The length as integer
        Throws:
        java.io.IOException - If invalid format found
      • readObject

        public ASN1Object readObject()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readBigInteger

        public java.math.BigInteger readBigInteger()
                                            throws java.io.IOException
        Throws:
        java.io.IOException