简体   繁体   English

如何在 Java 中生成 PGP 证书

[英]How to generate a PGP Certificate in Java

I am currently using Bouncy Castle library (1.45) for the generation of X509 Certificate (ie X509V1CertificateGenerator), and now I need to be able to create and import/export a PGP Certificate into/from the keystore.我目前正在使用 Bouncy Castle 库 (1.45) 来生成 X509 证书(即 X509V1CertificateGenerator),现在我需要能够创建 PGP 证书并将其导入/导出到密钥库中。 However, I am not seeing any support for the generation of a PGP Certificate in their "openpgp" package.但是,在他们的“openpgp”包中,我没有看到对生成 PGP 证书的任何支持。

All I am seeing is PGPKeyRingGenerator, PGPSignatureGenerator.我所看到的只是 PGPKeyRingGenerator、PGPSignatureGenerator。 I am open to using another Java library.我愿意使用另一个 Java 库。 Thank you very much.非常感谢。

Bouncy Castle can do that, you're just mixing up certificates vs. keys, as Eugene suggested. Bouncy Castle 可以做到这一点,正如 Eugene 建议的那样,您只是将证书与密钥混为一谈。

It's X509 Certificate, and an OpenPGP keypair.它是 X509 证书和 OpenPGP 密钥对。 Certificates are stored in a certificate store, and OpenPGP keys are stored in a keyring.证书存储在证书存储中,OpenPGP 密钥存储在密钥环中。

If you want to create such a PGP Keypair, see BouncyCastle Example of generating an OpenPGP Keypair .如果要创建这样的 PGP 密钥对,请参阅BouncyCastle 生成 OpenPGP 密钥对的示例

If you want to import the OpenPGP keypair you generated, you need to deal with a public keyring and a secret keyring (optional, if you have the private part of the key).如果你想导入你生成的 OpenPGP 密钥对,你需要处理一个公共密钥环和一个秘密密钥环(可选,如果你有密钥的私有部分)。

To import a foreign key, use PGPPublicKeyRing.insertPublicKey .要导入外键,请使用PGPPublicKeyRing.insertPublicKey To import a private key, use PGPSecretKeyRing.insertSecretKey .要导入私钥,请使用PGPSecretKeyRing.insertSecretKey

Those methods are static, be sure to generate a keyring beforhand (ie a certificate-store alike).这些方法是静态的,一定要预先生成一个密钥环(即类似的证书存储)。 Furthermore you should read about PGP's or gnupgs basic concecpt, before using these classes.此外,在使用这些类之前,您应该阅读 PGP 或 gnupgs 的基本概念。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM