Class PKCS8EncryptionHandler

java.lang.Object
com.unboundid.util.ssl.cert.PKCS8EncryptionHandler

This class provides a set of utility methods for interacting with encrypted PKCS #8 private keys.
  • Method Details

    • encryptPrivateKey

      @NotNull public static byte[] encryptPrivateKey(@NotNull PKCS8PrivateKey privateKey, @NotNull char[] encryptionPassword, @NotNull PKCS8EncryptionProperties encryptionProperties) throws CertException
      Encrypts the provided PKCS #8 private key using the provided settings.
      Parameters:
      privateKey - The private key to encrypt. It must not be null.
      encryptionPassword - The password to use to generate the encryption key. It must not be null.
      encryptionProperties - The properties to use when encrypting the key. It must not be null.
      Returns:
      The bytes that contain the DER-encoded encrypted representation of the private key.
      Throws:
      CertException - If a problem occurs while attempting to encrypt the provided certificate with the given settings.
    • encryptPrivateKey

      @NotNull public static byte[] encryptPrivateKey(@NotNull byte[] privateKeyBytes, @NotNull char[] encryptionPassword, @NotNull PKCS8EncryptionProperties encryptionProperties) throws CertException
      Encrypts the provided PKCS #8 private key using the provided settings.
      Parameters:
      privateKeyBytes - The bytes that comprise the private key to encrypt. It must not be null.
      encryptionPassword - The password to use to generate the encryption key. It must not be null.
      encryptionProperties - The properties to use when encrypting the key. It must not be null.
      Returns:
      The bytes that contain the DER-encoded encrypted representation of the private key.
      Throws:
      CertException - If a problem occurs while attempting to encrypt the provided certificate with the given settings.
    • decryptPrivateKey

      @NotNull public static PKCS8PrivateKey decryptPrivateKey(@NotNull byte[] encryptedPrivateKeyBytes, @NotNull char[] encryptionPassword) throws CertException
      Attempts to decrypt the provided data as a PKCS #8 private key.
      Parameters:
      encryptedPrivateKeyBytes - The bytes that comprise the encrypted representation of a PKCS #8 private key. It must not be null.
      encryptionPassword - The password used to generate the encryption key. It must not be null.
      Returns:
      The decrypted and decoded PKCS #8 private key.
      Throws:
      CertException - If a problem occurs while attempting to decrypt the encrypted private key.