Java生成pgp密钥对,java用bouncycastle签名公共pgp密钥

I've got a doubt..

I have to sign a pgp public key using bouncycastle api supposedly.

Now: to my understanding signing a key with another means ultimately adding to this public key a "certificate".

Thus lacking any other way, I've gone blind searching in the library.

my only find so far has been method generateCertification inside PGPSignatureGenerator. But this method generate a certification between a master PgpPublicKey and another PgpPublicKey.. And this strikes me as strange:

I assumed that in order to trust another public key, that has to be signed with your own private pgp key just like in regular x.509 with CA certification in a manner..

This was assumption by some methods that I saw when trying to get some ideas from other library: didisoft for example has a similar method on a keystore where you have to provide the PgpPrivatekey keyuid...

Anyone has any hint or a piece of code to propose?

Thanks in advance.

解决方案

Here's a Codeexample to sign a public Key:

PGPSecretKey mySecretKey;

PGPPublicKey publicKeyToBeSigned;

PGPPrivateKey pgpPrivKey = mySecretKey

.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder()

.setProvider("BC").build("password for your private key"));

PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(

new JcaPGPContentSignerBuilder(mySecretKey.getPublicKey()

.getAlgorithm(), PGPUtil.SHA512));

signatureGenerator.init(PGPSignature.DIRECT_KEY, pgpPrivKey);

PGPSignature signature = signatureGenerator.generateCertification(

id, publicKeyToBeSigned);

This piece of code just creates the signature. You need to add it to your the public key then:

PGPPublicKey.addCertification(publicKeyToBeSigned, signature);

Hope that helps you :)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值