public class P12PasswordProtection extends java.security.KeyStore.PasswordProtection implements P12Algorithms
PKCS#12 KeyStore.
P12 key entry protection parameters may be used to specify password and algorithm for protecting
a key entry when adding it to a PKCS#12 KeyStore, e.g.:
// the protection algorithm name
String protectionAlg = "PBES2";
// the keystore password
char[] password = ...;
// create a new PKCS12 KeyStore
KeyStore ks = KeyStore.getInstance("PKCS12", "IAIK");
ks.load(null, null);
// add a key entry
PrivateKey privateKey = ...;
X509Certificate[] certChain = ...;
String keyAlias = ...;
KeyStore.PrivateKeyEntry keyEntry = new KeyStore.PrivateKeyEntry(privateKey, certChain);
P12PasswordProtection pwdProtection = new P12PasswordProtection(password, protectionAlg);
ks.setEntry(keyAlias, keyEntry, pwdProtection);
// store keystore
OutputStream os = ...;
P12StoreParameter storeParams = new P12StoreParameter(os, password, protectionAlg);
ks.store(storeParams);
Although it is possible to use any specific supported PBES1 or
PBES2 algorithm, it is recommended to use the
"PBES2" (for security reasons) or
"PBES1" algorithm set (for backwards interoperability reasons to PKCS#12
applications that do not support PBES2 yet).P12KeyStoreP_ALG_DEFAULT, P_ALG_LEGACY, P_ALG_PBES1, P_ALG_PBES2, P_ALG_PBES2_PBMAC1| Constructor and Description |
|---|
P12PasswordProtection(char[] password)
Creates P12 password protection parameters for the given password.
|
P12PasswordProtection(char[] password,
java.lang.String protectionAlgorithm)
Creates P12 password protection parameters for the given password and algorithm.
|
public P12PasswordProtection(char[] password)
When using this constructor, the PBES2
algorithm set (with PBES2WithHmacSHA256AndAES256) is used to protect the key entry.
password - the passwordpublic P12PasswordProtection(char[] password,
java.lang.String protectionAlgorithm)
throws java.security.NoSuchAlgorithmException
protectionAlgorithm - the name of the protection algorithm (set) to be used,
e.g. "PBES2" or "PBES1"java.security.NoSuchAlgorithmException - if the requested algorithm (set) is not supported