Interface PrivateKeyPasswordBasedEncryptor


  • @Role
    public interface PrivateKeyPasswordBasedEncryptor
    Manage encryption of private keys using password based ciphers as defined in PKCS #8.
    Since:
    5.4RC1
    Version:
    $Id: ed7c544be6fc8bdad9f908c9a1a363f373d05e6c $
    • Method Detail

      • decrypt

        PrivateKeyParameters decrypt​(byte[] password,
                                     byte[] encoded)
                              throws GeneralSecurityException,
                                     IOException
        Decrypt a private key from an encoded byte array.
        Parameters:
        password - the password used to derive the encryption key.
        encoded - the encrypted key in ASN.1 format according to PKCS #8.
        Returns:
        decrypted private key parameters.
        Throws:
        GeneralSecurityException - if an error occurs during decryption.
        IOException - if an error occurs during decoding.
      • encrypt

        byte[] encrypt​(String algHint,
                       SymmetricCipherParameters password,
                       KeyDerivationFunction function,
                       PrivateKeyParameters privateKey)
                throws GeneralSecurityException,
                       IOException
        Encrypt a private key using a password based cipher in a PKCS #8 format.
        Parameters:
        algHint - the hint of the PasswordBasedCipher to use.
        password - cipher parameters, using a password converted to bytes for the key.
        function - the key derivation function to use for deriving key from password.
        privateKey - cipher parameters, using a password converted to bytes for the key.
        Returns:
        the encrypted key in ASN.1 format according to PKCS #8.
        Throws:
        GeneralSecurityException - if an error occurs during encryption.
        IOException - if an error occurs during encoding.
      • encrypt

        byte[] encrypt​(String algHint,
                       byte[] password,
                       byte[] encoded,
                       PrivateKeyParameters privateKey)
                throws GeneralSecurityException,
                       IOException
        Encrypt a private key using a password based cipher in a PKCS #8 format.
        Parameters:
        algHint - the hint of the PasswordBasedCipher to use.
        password - the password used to derive the encryption key.
        encoded - encoded parameters to initialize the cipher and derivation function.
        privateKey - the private key parameters to encrypt.
        Returns:
        the encrypted key in ASN.1 format according to PKCS #8.
        Throws:
        GeneralSecurityException - if an error occurs during encryption.
        IOException - if an error occurs during encoding.
      • encrypt

        byte[] encrypt​(byte[] password,
                       PrivateKeyParameters privateKey)
                throws GeneralSecurityException,
                       IOException
        Encrypt a private key using a AES 256 password based cipher in a PKCS #8 format.
        Parameters:
        password - the password used to derive the encryption key.
        privateKey - the private key parameters to encrypt.
        Returns:
        the encrypted key in ASN.1 format according to PKCS #8.
        Throws:
        GeneralSecurityException - if an error occurs during encryption.
        IOException - if an error occurs during encoding.
      • encrypt

        byte[] encrypt​(String algHint,
                       byte[] password,
                       KeyDerivationFunctionParameters kdfParameters,
                       PrivateKeyParameters privateKey)
                throws IOException,
                       GeneralSecurityException
        Encrypt a private key in a PKCS #8 format using a random initialization vector.
        Parameters:
        algHint - the hint of the PasswordBasedCipher to use.
        password - the password used to derive the encryption key.
        kdfParameters - the parameters of the derivation function.
        privateKey - the private key parameters to encrypt.
        Returns:
        the encrypted key in ASN.1 format according to PKCS #8.
        Throws:
        GeneralSecurityException - if an error occurs during encryption.
        IOException - if an error occurs during encoding.