Class PEMTools

java.lang.Object
convex.core.crypto.PEMTools

public class PEMTools extends Object
  • Constructor Details

    • PEMTools

      public PEMTools()
  • Method Details

    • writePEM

      public static String writePEM(AKeyPair kp)
      Writes a key pair to a String
      Parameters:
      kp - Key pair to write
      Returns:
      PEM String representation of key pair
    • readPEM

      public static AKeyPair readPEM(String pem) throws GeneralSecurityException
      Read a key pair from a PEM String
      Parameters:
      pem - PEM String
      Returns:
      Key pair instance
      Throws:
      GeneralSecurityException - If a security error occurs
    • encryptPrivateKeyToPEM

      public static String encryptPrivateKeyToPEM(PrivateKey privateKey, char[] password) throws Error
      Encrypt a priavte key into a PEM formated text
      Parameters:
      privateKey - Private key to encrypt
      password - Password to use for encryption
      Returns:
      PEM text that can be saved or sent to another keystore
      Throws:
      Error - Any encryption error that occurs
    • decryptPrivateKeyFromPEM

      public static PrivateKey decryptPrivateKeyFromPEM(String pemText, char[] password) throws Error
      Decrypt a PEM string to a private key. The PEM string must contain the "ENCRYPTED PRIVATE KEY" type.
      Parameters:
      pemText - PEM string to decode
      password - Password that was used to encrypt the private key
      Returns:
      PrivateKey stored in the PEM
      Throws:
      Error - on reading the PEM, decryption and decoding the private key
    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception