Class PEMDecoder

java.lang.Object
org.webpki.util.PEMDecoder

public class PEMDecoder extends Object
Decodes PEM files.
  • Method Details

    • getKeyPair

      public static KeyPair getKeyPair(byte[] pemBlob)
      Returns a java KeyPair.

      Note that this method presumes that there is one PRIVATE KEY present and that is in the extended PKCS #8 format that also holds the associated public key. The latter only applies to EC and OKP keys since public key is implicit for RSA private keys. However, if there is a PUBLIC KEY element as well, this takes precedence over public keys suppled in PKCS #8 extensions. ED25519 keys generated by OpenSSL seem to require such an arrangement.

      Parameters:
      pemBlob - PEM input
      Returns:
      Key pair
      Throws:
      CryptoException
    • getPrivateKey

      public static PrivateKey getPrivateKey(byte[] pemBlob)
      Returns a java PrivateKey.

      Note that this method presumes that there is one PRIVATE KEY present and uses the PKCS #8 format.

      Parameters:
      pemBlob - PEM input
      Returns:
      Private key
      Throws:
      CryptoException
    • getPublicKey

      public static PublicKey getPublicKey(byte[] pemBlob)
      Returns a java PublicKey.

      Note that this method presumes that there is one PUBLIC KEY present.

      Parameters:
      pemBlob - PEM input
      Returns:
      Public key
      Throws:
      CryptoException
    • getCertificatePath

      public static X509Certificate[] getCertificatePath(byte[] pemBlob)
      Returns a java X509Certificate path.

      Note that this method presumes that there is one or more CERTIFICATE elements present. The certificates are checked for path conformance, including verifying that they are listed in the PEM file in ascending order.

      Parameters:
      pemBlob - PEM input
      Returns:
      Certficate path
      Throws:
      CryptoException
    • getKeyStore

      public static KeyStore getKeyStore(byte[] pemBlob, String alias, String password)
      Returns a java KeyStore.

      Note that this method depends on getCertificatePath(byte[]) and getPrivateKey(byte[]).

      Parameters:
      pemBlob - PEM input
      Returns:
      Initialized KeyStore
      Throws:
      CryptoException