Java Bouncy castle密钥生成器示例错误

Java Bouncy castle密钥生成器示例错误,java,bouncycastle,Java,Bouncycastle,我正在尝试使用bouncy castle pgp生成密钥对。 我用这个例子: 但我在电话里遇到了一个我无法理解/解决的错误 PGPSecretKey secretKey = new PGPSecretKey(PGPSignature.DEFAULT_CERTIFICATION, PGPPublicKey.RSA_GENERAL, publicKey, privateKey, new Date(), identity, PGPEncryptedData.CAST5, passPhrase,

我正在尝试使用bouncy castle pgp生成密钥对。 我用这个例子:

但我在电话里遇到了一个我无法理解/解决的错误

 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)
错误:(43,37)java:找不到适合PGPSecretKey的构造函数(int,int,java.security.PublicKey,java.security.PrivateKey,java.util.Date,java.lang.String,int,char[],java.security.SecureRandom,java.lang.String)
构造函数org.bouncycastle.openpgp.PGPSecretKey.PGPSecretKey(org.bouncycastle.bcpg.SecretKeyPacket,org.bouncycastle.openpgp.PGPPublicKey)不适用
(实际参数列表和正式参数列表长度不同)
构造函数org.bouncycastle.openpgp.PGPSecretKey.PGPSecretKey(org.bouncycastle.openpgp.PGPPrivateKey,org.bouncycastle.openpgp.PGPPublicKey,org.bouncycastle.openpgp.operator.PGPDigestCalculator,org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor)不适用
(实际参数列表和正式参数列表长度不同)
构造函数org.bouncycastle.openpgp.PGPSecretKey.PGPSecretKey(org.bouncycastle.openpgp.PGPPrivateKey,org.bouncycastle.openpgp.PGPPublicKey,org.bouncycastle.openpgp.operator.PGPDigestCalculator,boolean,org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor)不适用
(实际参数列表和正式参数列表长度不同)
构造函数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)不适用
(实际参数列表和正式参数列表长度不同)
构造函数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.operator.PGPContentSignerBuilder,org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor)不适用
(实际参数列表和正式参数列表长度不同)

谢谢

您使用的是1.45版,它非常旧,当前的版本是1.58

正如@Hulk正确推测的那样,您似乎在引用Javadoc以获得更高版本,该版本具有12个参数的构造函数。该构造函数在1.45中不存在


将POM更新为参考版本1.58。

您使用的是版本1.45,它非常旧,当前版本是1.58

正如@Hulk正确推测的那样,您似乎在引用Javadoc以获得更高版本,该版本具有12个参数的构造函数。该构造函数在1.45中不存在


将POM更新为引用版本1.58。

好吧,您导入的类中似乎没有12个参数的构造函数。也许您用作引用的JavaDocs与您实际使用的版本不匹配?好吧,您导入的类中似乎没有12个参数的构造函数。也许您用作r的JavaDocs引用与您实际使用的版本不匹配?