Class PEMDecoder

java.lang.Object
com.trilead.ssh2.crypto.PEMDecoder

public class PEMDecoder extends 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 Details

    • PEMDecoder

      public PEMDecoder()
  • Method Details

    • hexToByteArray

      public static byte[] hexToByteArray(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 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:
      IOException
    • decryptPEM

      public static void decryptPEM(PEMStructure ps, String password) throws 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:
      IOException
    • isPEMEncrypted

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

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

      public static KeyPair decodeKeyPair(char[] pem, String password) throws 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:
      IOException