use of org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfoBuilder in project xipki by xipki.
the class PrivateKeyCryptor method encrypt.
PKCS8EncryptedPrivateKeyInfo encrypt(PrivateKey privateKey) {
ParamUtil.requireNonNull("privateKey", privateKey);
PrivateKeyInfo privateKeyInfo = PrivateKeyInfo.getInstance(privateKey.getEncoded());
PKCS8EncryptedPrivateKeyInfoBuilder builder = new PKCS8EncryptedPrivateKeyInfoBuilder(privateKeyInfo);
synchronized (encryptor) {
return builder.build(encryptor);
}
}
use of org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfoBuilder in project certmgr by hdecarne.
the class DERCertReaderWriter method encryptKey.
private static byte[] encryptKey(KeyPair key, String resource, PasswordCallback newPassword) throws IOException {
char[] passwordChars = newPassword.queryPassword(resource);
if (passwordChars == null) {
throw new PasswordRequiredException(resource);
}
byte[] encoded;
try {
PKCS8EncryptedPrivateKeyInfoBuilder encryptedPrivateKeyInfoBuilder = new PKCS8EncryptedPrivateKeyInfoBuilder(KeyHelper.encodePrivateKey(key.getPrivate()));
OutputEncryptor encryptor = OUTPUT_ENCRYPTOR_BUILDER.build(passwordChars);
encoded = encryptedPrivateKeyInfoBuilder.build(encryptor).getEncoded();
} catch (OperatorCreationException e) {
throw new CertProviderException(e);
}
return encoded;
}
Aggregations