/** * Returns an {@code EncryptedPrivateKeyInfo} from a given PrivateKey. * A valid password-based encryption (PBE) algorithm and password must be * specified. AlgorithmParameterSpec, {@code params}, will use the * provider default if {@code null} is passed. If {@code provider} is * {@code null}, the provider will be selected through the default * provider list. *

* The PBE algorithm string format details can be found in the * * Cipher section of the Java Security Standard Algorithm Names * Specification. * * @param key the PrivateKey object to encrypt. * @param password the password used for generating the PBE key. * @param algorithm the PBE encryption algorithm. * @param params the parameters used with the PBE encryption. * @param provider the Provider that will perform the encryption. * @return an EncryptedPrivateKeyInfo. * @throws IllegalArgumentException when arguments passed are incorrect. * @throws SecurityException on a cryptographic errors. * @throws NullPointerException if an argument passed in is unexpectedly null. * * @since 24 */ @PreviewFeature(feature = PreviewFeature.Feature.PEM_API) public static EncryptedPrivateKeyInfo encryptKey(PrivateKey key, char[] password, String algorithm, AlgorithmParameterSpec params, Provider provider) { /** * Creates and encrypts an `EncryptedPrivateKeyInfo` from a given PrivateKey * and password. *

* The encryption uses the algorithm set by `jdk.epkcs8.defaultAlgorithm` * Security Property by the default provider and default the * AlgorithmParameterSpec of that provider. * * @param key The PrivateKey object to encrypt. * @param password the password used in the PBE encryption. * @return an EncryptedPrivateKeyInfo. * @throws IllegalArgumentException when arguments passed are incorrect. * @throws SecurityException on a cryptographic errors. * * @since 24 */ @PreviewFeature(feature = PreviewFeature.Feature.PEM_API) public static EncryptedPrivateKeyInfo encryptKey(PrivateKey key, char[] password) { /** * Return a PrivateKey from the encrypted data in the object. * * @param password the password used in the PBE encryption. * @return a PrivateKey * @throws InvalidKeyException if an error occurs during parsing of the * encrypted data or creation of the key object. * * @since 24 */ @PreviewFeature(feature = PreviewFeature.Feature.PEM_API) public PrivateKey getKey(char[] password) throws InvalidKeyException { /** * Return a PrivateKey from the object's encrypted data with a KeyFactory * from the given Provider. * * @param password the password * @param provider the KeyFactory provider used to generate the key. * @return a PrivateKey * @throws InvalidKeyException if an error occurs during parsing of the * encrypted data or creation of the key object. * * @since 24 */ @PreviewFeature(feature = PreviewFeature.Feature.PEM_API) public PrivateKey getKey(char[] password, Provider provider) throws InvalidKeyException {