充气城堡密钥生成器示例错误

Bouncy castle key generator example error

我正在尝试使用 bouncy castle pgp 生成密钥对。 我用这个例子:http://grepcode.com/file/repo1.maven.org/maven2/org.bouncycastle/bcpg-jdk15/1.45/org/bouncycastle/openpgp/examples/RSAKeyPairGenerator.java

但是我遇到了一个我无法理解/解决的错误

 PGPSecretKey    secretKey = new PGPSecretKey(PGPSignature.DEFAULT_CERTIFICATION, PGPPublicKey.RSA_GENERAL, publicKey, privateKey, new Date(), identity, PGPEncryptedData.CAST5, passPhrase, null, null, new SecureRandom(), "BC");

无法解析构造函数... 但是,如果我查看 java 文档,我觉得还不错...

编译器错误

Error:(43, 37) java: no suitable constructor found for PGPSecretKey(int,int,java.security.PublicKey,java.security.PrivateKey,java.util.Date,java.lang.String,int,char[],<nulltype>,<nulltype>,java.security.SecureRandom,java.lang.String)
    constructor org.bouncycastle.openpgp.PGPSecretKey.PGPSecretKey(org.bouncycastle.bcpg.SecretKeyPacket,org.bouncycastle.openpgp.PGPPublicKey) is not applicable
      (actual and formal argument lists differ in length)
    constructor org.bouncycastle.openpgp.PGPSecretKey.PGPSecretKey(org.bouncycastle.openpgp.PGPPrivateKey,org.bouncycastle.openpgp.PGPPublicKey,org.bouncycastle.openpgp.operator.PGPDigestCalculator,org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor) is not applicable
      (actual and formal argument lists differ in length)
    constructor org.bouncycastle.openpgp.PGPSecretKey.PGPSecretKey(org.bouncycastle.openpgp.PGPPrivateKey,org.bouncycastle.openpgp.PGPPublicKey,org.bouncycastle.openpgp.operator.PGPDigestCalculator,boolean,org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor) is not applicable
      (actual and formal argument lists differ in length)
    constructor org.bouncycastle.openpgp.PGPSecretKey.PGPSecretKey(int,org.bouncycastle.openpgp.PGPKeyPair,java.lang.String,org.bouncycastle.openpgp.PGPSignatureSubpacketVector,org.bouncycastle.openpgp.PGPSignatureSubpacketVector,org.bouncycastle.openpgp.operator.PGPContentSignerBuilder,org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor) is not applicable
      (actual and formal argument lists differ in length)
    constructor org.bouncycastle.openpgp.PGPSecretKey.PGPSecretKey(int,org.bouncycastle.openpgp.PGPKeyPair,java.lang.String,org.bouncycastle.openpgp.operator.PGPDigestCalculator,org.bouncycastle.openpgp.PGPSignatureSubpacketVector,org.bouncycastle.openpgp.PGPSignatureSubpacketVector,org.bouncycastle.openpgp.operator.PGPContentSignerBuilder,org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor) is not applicable
      (actual and formal argument lists differ in length)

谢谢

您使用的是1.45版本,比较旧,当前版本是1.58。

正如@Hulk 正确推测的那样,您似乎指的是更高版本的 Javadoc,它具有 12 个参数的构造函数。此构造函数在 1.45 中不存在。

将您的 POM 更新为参考版本 1.58。