【问题标题】:how to generate PGP key revoke in java and Bouncy Castle如何在 java 和 Bouncy Castle 中生成 PGP 密钥撤销
【发布时间】:2018-06-22 18:44:39
【问题描述】:

我想生成吊销证书以及公钥和私钥对生成。

正确生成私钥和公钥。

我试着这样做:

public void generateRevoke(String id, PGPPublicKey pk, PGPSecretKey secretKey, char[] passPhrase, OutputStream out) throws PGPException, IOException {

    PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(
            new JcaPGPContentSignerBuilder(secretKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1));

    PGPPrivateKey pgpPrivKey = secretKey.extractPrivateKey(
            new JcePBESecretKeyDecryptorBuilder().setProvider(new BouncyCastleProvider())
                    .build(passPhrase));

    signatureGenerator.init(PGPSignature.KEY_REVOCATION, pgpPrivKey);

    PGPSignature signature = signatureGenerator.generateCertification(id, pk);

    PGPPublicKey key = PGPPublicKey.addCertification(pk, id, signature);

    key.encode(new ArmoredOutputStream(out));
}

但在输出文件中我得到的是 PGP MESSAGE 而不是 PGP PUBLIC KEY

我做错了什么?

【问题讨论】:

    标签: java bouncycastle pgp


    【解决方案1】:

    我解决问题。正确的方法返回带有撤销证书的公钥:

    public void generateRevoke(String id, PGPSecretKey secretKey, char[] passPhrase, OutputStream out) throws PGPException, IOException {
    
        PGPPublicKey oldKey = secretKey.getPublicKey();
    
        PGPPrivateKey pgpPrivKey = secretKey.extractPrivateKey(
                new JcePBESecretKeyDecryptorBuilder().setProvider( provider )
                        .build(passPhrase));
    
        PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(
                new JcaPGPContentSignerBuilder( secretKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1 ) );
    
        signatureGenerator.init( PGPSignature.CERTIFICATION_REVOCATION, pgpPrivKey );
    
        PGPSignature signature = signatureGenerator.generateCertification(id, oldKey);
    
        PGPPublicKey newKey = PGPPublicKey.addCertification(oldKey, id, signature);
    
        out = new ArmoredOutputStream(out);
    
        newKey.encode(out);
        out.close();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-25
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 2019-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多