Class PEMDecoder


  • public class PEMDecoder
    extends java.lang.Object
    PEM Support.
    Version:
    $Id: PEMDecoder.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $
    Author:
    Christian Plattner, plattner@trilead.com
    • Constructor Summary

      Constructors 
      Constructor Description
      PEMDecoder()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static java.lang.Object decode​(char[] pem, java.lang.String password)
      Deprecated.
      use PEMDecoder.decodeKeyPair
      static java.security.KeyPair decodeKeyPair​(char[] pem, java.lang.String password)
      Extract a key pair from a PEM file.
      static void decryptPEM​(PEMStructure ps, java.lang.String password)
      Decrypt a key in a PEMStructure and store the unencrypted key decrypted in the PEMStructure.
      static byte[] hexToByteArray​(java.lang.String hex)
      convert an hexadecimal number in a string to its bytes.
      static boolean isPEMEncrypted​(PEMStructure ps)
      Check if a Key is encrypted.
      static PEMStructure parsePEM​(char[] pem)
      Process a PEM file and construct a PEMStructure.
      • Methods inherited from class java.lang.Object

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

      • PEMDecoder

        public PEMDecoder()
    • Method Detail

      • hexToByteArray

        public static byte[] hexToByteArray​(java.lang.String hex)
        convert an hexadecimal number in a string to its bytes.
        Parameters:
        hex - hexadecimal number in a string.
        Returns:
        Array of bytes.
      • parsePEM

        public static PEMStructure parsePEM​(char[] pem)
                                     throws java.io.IOException
        Process a PEM file and construct a PEMStructure. It works with RSA and DSA keys.
        Parameters:
        pem - PEM file content.
        Returns:
        PEMStructure with the PEM file data parsed.
        Throws:
        java.io.IOException
      • decryptPEM

        public static void decryptPEM​(PEMStructure ps,
                                      java.lang.String password)
                               throws java.io.IOException
        Decrypt a key in a PEMStructure and store the unencrypted key decrypted in the PEMStructure.
        Parameters:
        ps - PEMStructure structure to load the PEM data.
        password - password to decrypt the Key.
        Throws:
        java.io.IOException
      • isPEMEncrypted

        public static boolean isPEMEncrypted​(PEMStructure ps)
                                      throws java.io.IOException
        Check if a Key is encrypted.
        Parameters:
        ps - PEMStructure structure to load the PEM data.
        Returns:
        true if it is encrypted.
        Throws:
        java.io.IOException
      • decode

        @Deprecated
        public static java.lang.Object decode​(char[] pem,
                                              java.lang.String password)
                                       throws java.io.IOException
        Deprecated.
        use PEMDecoder.decodeKeyPair
        return a RSA or a DSA Key from a PEM data.
        Throws:
        java.io.IOException
      • decodeKeyPair

        public static java.security.KeyPair decodeKeyPair​(char[] pem,
                                                          java.lang.String password)
                                                   throws java.io.IOException
        Extract a key pair from a PEM file.
        Parameters:
        pem - PEMStructure structure to load the PEM data.
        password - password to decrypt the Key.
        Returns:
        keypair from the PEM file.
        Throws:
        java.io.IOException