当前位置: 首页>>代码示例>>Java>>正文


Java PGPSecretKeyRing.getSecretKey方法代码示例

本文整理汇总了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.");
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:26,代码来源:PGP.java

示例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));
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:18,代码来源:X509Bridge.java

示例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.");
}
 
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:27,代码来源:PGP.java

示例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);
}
 
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:19,代码来源:X509Bridge.java

示例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);
}
 
开发者ID:guardianproject,项目名称:proofmode,代码行数:6,代码来源:PgpUtils.java


注:本文中的org.spongycastle.openpgp.PGPSecretKeyRing.getSecretKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。