本文整理汇总了Java中org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8DecryptorProviderBuilder类的典型用法代码示例。如果您正苦于以下问题:Java JceOpenSSLPKCS8DecryptorProviderBuilder类的具体用法?Java JceOpenSSLPKCS8DecryptorProviderBuilder怎么用?Java JceOpenSSLPKCS8DecryptorProviderBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JceOpenSSLPKCS8DecryptorProviderBuilder类属于org.bouncycastle.openssl.jcajce包,在下文中一共展示了JceOpenSSLPKCS8DecryptorProviderBuilder类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getPrivateKey
import org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8DecryptorProviderBuilder; //导入依赖的package包/类
public static PrivateKey getPrivateKey(String keyString) {
PrivateKey privateKey = null;
try {
BufferedReader br = new BufferedReader(new StringReader(keyString));
PEMParser pp = new PEMParser(br);
PKCS8EncryptedPrivateKeyInfo pemPrivateKeyInfo = (PKCS8EncryptedPrivateKeyInfo) pp.readObject();
pp.close();
InputDecryptorProvider pkcs8Prov = new JceOpenSSLPKCS8DecryptorProviderBuilder().build("1234".toCharArray());
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
privateKey = converter.getPrivateKey(pemPrivateKeyInfo.decryptPrivateKeyInfo(pkcs8Prov));
} catch (Exception e) {
ProtoLogger.error("!!! Error importing private key !!!");
}
return privateKey;
}
开发者ID:satispay,项目名称:in-store-api-java-sdk,代码行数:25,代码来源:CryptoUtils.java
示例2: parsePrivateKey
import org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8DecryptorProviderBuilder; //导入依赖的package包/类
/**
* Parses a PrivateKey instance from a PEM representation.
*
* When the provided key is encrypted, the provided pass phrase is applied.
*
* @param pemRepresentation a PEM representation of a private key (cannot be null or empty)
* @param passPhrase optional pass phrase (must be present if the private key is encrypted).
* @return a PrivateKey instance (never null)
*/
public static PrivateKey parsePrivateKey(InputStream pemRepresentation, String passPhrase) throws IOException {
if ( passPhrase == null ) {
passPhrase = "";
}
try (Reader reader = new InputStreamReader(pemRepresentation); //
PEMParser pemParser = new PEMParser(reader)) {
final Object object = pemParser.readObject();
final JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider( "BC" );
final KeyPair kp;
if ( object instanceof PEMEncryptedKeyPair )
{
// Encrypted key - we will use provided password
final PEMDecryptorProvider decProv = new JcePEMDecryptorProviderBuilder().build( passPhrase.toCharArray() );
kp = converter.getKeyPair( ( (PEMEncryptedKeyPair) object ).decryptKeyPair( decProv ) );
}
else if ( object instanceof PKCS8EncryptedPrivateKeyInfo )
{
// Encrypted key - we will use provided password
try
{
final PKCS8EncryptedPrivateKeyInfo encryptedInfo = (PKCS8EncryptedPrivateKeyInfo) object;
final InputDecryptorProvider provider = new JceOpenSSLPKCS8DecryptorProviderBuilder().build( passPhrase.toCharArray() );
final PrivateKeyInfo privateKeyInfo = encryptedInfo.decryptPrivateKeyInfo( provider );
return converter.getPrivateKey( privateKeyInfo );
}
catch ( PKCSException | OperatorCreationException e )
{
throw new IOException( "Unable to decrypt private key.", e );
}
}
else if ( object instanceof PrivateKeyInfo )
{
return converter.getPrivateKey( (PrivateKeyInfo) object );
}
else
{
// Unencrypted key - no password needed
kp = converter.getKeyPair( (PEMKeyPair) object );
}
return kp.getPrivate();
}
}
开发者ID:igniterealtime,项目名称:Openfire,代码行数:56,代码来源:CertificateManager.java
注:本文中的org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8DecryptorProviderBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论