Class AbstractPrivateKeyDecoder<T>

java.lang.Object
org.cryptacular.asn.AbstractPrivateKeyDecoder<T>
Type Parameters:
T - Type produced by decode operation.
All Implemented Interfaces:
ASN1Decoder<T>
Direct Known Subclasses:
OpenSSLPrivateKeyDecoder, PKCS8PrivateKeyDecoder

public abstract class AbstractPrivateKeyDecoder<T> extends Object implements ASN1Decoder<T>
Base class for all private key decoders.
Author:
Middleware Services
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    decode(byte[] encoded, Object... args)
    Produces an object from an encoded representation.
    protected abstract T
    decodeASN1(byte[] encoded)
    Decodes the given raw ASN.1 encoded data into a private key of the type supported by this class.
    protected abstract byte[]
    decryptKey(byte[] encrypted, char[] password)
    Decrypts an encrypted key in either PKCS#8 or OpenSSL "traditional" format.
    protected byte[]
    tryConvertPem(byte[] input)
    Tests the given encoded input and converts it to PEM if it is detected, stripping out any header/footer data in the process.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractPrivateKeyDecoder

      public AbstractPrivateKeyDecoder()
  • Method Details

    • decode

      public T decode(byte[] encoded, Object... args) throws EncodingException
      Description copied from interface: ASN1Decoder
      Produces an object from an encoded representation.
      Specified by:
      decode in interface ASN1Decoder<T>
      Parameters:
      encoded - ASN.1 encoded data.
      args - Additional data required to perform decoding.
      Returns:
      Decoded object.
      Throws:
      EncodingException - on encoding errors.
    • tryConvertPem

      protected byte[] tryConvertPem(byte[] input)
      Tests the given encoded input and converts it to PEM if it is detected, stripping out any header/footer data in the process.
      Parameters:
      input - Encoded data that may be PEM encoded.
      Returns:
      Decoded data if PEM encoding detected, otherwise original data.
    • decryptKey

      protected abstract byte[] decryptKey(byte[] encrypted, char[] password)
      Decrypts an encrypted key in either PKCS#8 or OpenSSL "traditional" format. Both PEM and DER encodings are supported.
      Parameters:
      encrypted - Encoded encrypted key data.
      password - Password to decrypt key.
      Returns:
      Decrypted key.
    • decodeASN1

      protected abstract T decodeASN1(byte[] encoded)
      Decodes the given raw ASN.1 encoded data into a private key of the type supported by this class.
      Parameters:
      encoded - Encoded ASN.1 data.
      Returns:
      Private key object.