本文整理汇总了Java中org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfoBuilder类的典型用法代码示例。如果您正苦于以下问题:Java PKCS8EncryptedPrivateKeyInfoBuilder类的具体用法?Java PKCS8EncryptedPrivateKeyInfoBuilder怎么用?Java PKCS8EncryptedPrivateKeyInfoBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PKCS8EncryptedPrivateKeyInfoBuilder类属于org.bouncycastle.pkcs包,在下文中一共展示了PKCS8EncryptedPrivateKeyInfoBuilder类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encryptKey
import org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfoBuilder; //导入依赖的package包/类
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;
}
示例2: encrypt
import org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfoBuilder; //导入依赖的package包/类
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);
}
}
示例3: testBcEncryptedPrivateKeyInfo
import org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfoBuilder; //导入依赖的package包/类
public void testBcEncryptedPrivateKeyInfo()
throws Exception
{
KeyFactory fact = KeyFactory.getInstance("RSA", BC);
PrivateKey privKey = fact.generatePrivate(privKeySpec);
PKCS8EncryptedPrivateKeyInfoBuilder builder = new JcaPKCS8EncryptedPrivateKeyInfoBuilder(privKey);
PKCS8EncryptedPrivateKeyInfo priv = builder.build(new BcPKCS12PBEOutputEncryptorBuilder(PKCSObjectIdentifiers.pbeWithSHAAnd3_KeyTripleDES_CBC, new CBCBlockCipher(new DESedeEngine())).build(passwd));
PrivateKeyInfo info = priv.decryptPrivateKeyInfo(new BcPKCS12PBEInputDecryptorProviderBuilder().build(passwd));
assertTrue(Arrays.areEqual(info.getEncoded(), privKey.getEncoded()));
}
示例4: testEncryptedPrivateKeyInfo
import org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfoBuilder; //导入依赖的package包/类
public void testEncryptedPrivateKeyInfo()
throws Exception
{
KeyFactory fact = KeyFactory.getInstance("RSA", BC);
PrivateKey privKey = fact.generatePrivate(privKeySpec);
PKCS8EncryptedPrivateKeyInfoBuilder builder = new JcaPKCS8EncryptedPrivateKeyInfoBuilder(privKey);
PKCS8EncryptedPrivateKeyInfo priv = builder.build(new JcePKCSPBEOutputEncryptorBuilder(PKCSObjectIdentifiers.pbeWithSHAAnd3_KeyTripleDES_CBC).build(passwd));
PrivateKeyInfo info = priv.decryptPrivateKeyInfo(new JcePKCSPBEInputDecryptorProviderBuilder().build(passwd));
assertTrue(Arrays.areEqual(info.getEncoded(), privKey.getEncoded()));
}
示例5: testEncryptedPrivateKeyInfoPKCS5
import org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfoBuilder; //导入依赖的package包/类
public void testEncryptedPrivateKeyInfoPKCS5()
throws Exception
{
KeyFactory fact = KeyFactory.getInstance("RSA", BC);
PrivateKey privKey = fact.generatePrivate(privKeySpec);
PKCS8EncryptedPrivateKeyInfoBuilder builder = new JcaPKCS8EncryptedPrivateKeyInfoBuilder(privKey);
PKCS8EncryptedPrivateKeyInfo priv = builder.build(new JcePKCSPBEOutputEncryptorBuilder(NISTObjectIdentifiers.id_aes256_CBC).build(passwd));
PrivateKeyInfo info = priv.decryptPrivateKeyInfo(new JcePKCSPBEInputDecryptorProviderBuilder().build(passwd));
assertTrue(Arrays.areEqual(info.getEncoded(), privKey.getEncoded()));
}