本文整理汇总了Java中org.spongycastle.openpgp.PGPSecretKeyRing.getSecretKey方法的典型用法代码示例。如果您正苦于以下问题:Java PGPSecretKeyRing.getSecretKey方法的具体用法?Java PGPSecretKeyRing.getSecretKey怎么用?Java PGPSecretKeyRing.getSecretKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongycastle.openpgp.PGPSecretKeyRing
的用法示例。
在下文中一共展示了PGPSecretKeyRing.getSecretKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertPrivateKey
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static PrivateKey convertPrivateKey(byte[] privateKeyData, String passphrase)
throws PGPException, IOException {
PGPDigestCalculatorProvider digestCalc = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(digestCalc)
.setProvider(PGP.PROVIDER)
.build(passphrase.toCharArray());
// load the secret key ring
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, sFingerprintCalculator);
// search and decrypt the master (signing key)
// secret keys
Iterator<PGPSecretKey> skeys = secRing.getSecretKeys();
while (skeys.hasNext()) {
PGPSecretKey key = skeys.next();
PGPSecretKey sec = secRing.getSecretKey();
if (key.isMasterKey())
return convertPrivateKey(sec.extractPrivateKey(decryptor));
}
throw new PGPException("no suitable private key found.");
}
示例2: createCertificate
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入方法依赖的package包/类
public static X509Certificate createCertificate(byte[] privateKeyData, byte[] publicKeyData, String passphrase)
throws PGPException, IOException, InvalidKeyException, IllegalStateException,
NoSuchAlgorithmException, SignatureException, CertificateException, NoSuchProviderException, OperatorCreationException {
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, sFingerprintCalculator);
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(publicKeyData, sFingerprintCalculator);
PGPDigestCalculatorProvider sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(sha1Calc)
.setProvider(PGP.PROVIDER)
.build(passphrase.toCharArray());
// secret key
PGPSecretKey secKey = secRing.getSecretKey();
return createCertificate(pubRing, secKey.extractPrivateKey(decryptor));
}
示例3: convertPrivateKey
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static PrivateKey convertPrivateKey(byte[] privateKeyData, String passphrase)
throws PGPException, IOException {
PGPDigestCalculatorProvider sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(sha1Calc)
.setProvider(PGP.PROVIDER)
.build(passphrase.toCharArray());
// load the secret key ring
KeyFingerPrintCalculator fpr = new BcKeyFingerprintCalculator();
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, fpr);
// search and decrypt the master (signing key)
// secret keys
Iterator<PGPSecretKey> skeys = secRing.getSecretKeys();
while (skeys.hasNext()) {
PGPSecretKey key = skeys.next();
PGPSecretKey sec = secRing.getSecretKey();
if (key.isMasterKey())
return convertPrivateKey(sec.extractPrivateKey(decryptor));
}
throw new PGPException("no suitable private key found.");
}
示例4: createCertificate
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入方法依赖的package包/类
public static X509Certificate createCertificate(byte[] privateKeyData, byte[] publicKeyData, String passphrase, String subjectAltName)
throws PGPException, IOException, InvalidKeyException, IllegalStateException,
NoSuchAlgorithmException, SignatureException, CertificateException, NoSuchProviderException {
KeyFingerPrintCalculator fpr = new BcKeyFingerprintCalculator();
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, fpr);
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(publicKeyData, fpr);
PGPDigestCalculatorProvider sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(sha1Calc)
.setProvider(PGP.PROVIDER)
.build(passphrase.toCharArray());
// secret key
PGPSecretKey secKey = secRing.getSecretKey();
return createCertificate(pubRing, secKey.extractPrivateKey(decryptor), subjectAltName);
}
示例5: getPrivateKey
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入方法依赖的package包/类
private static PGPPrivateKey getPrivateKey(PGPSecretKeyRing keyRing, long keyID, char[] pass) throws PGPException {
PGPSecretKey secretKey = keyRing.getSecretKey(keyID);
PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(pass);
return secretKey.extractPrivateKey(decryptor);
}