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

时间:2017-11-22 23:42:34

标签: java bouncycastle

我正在尝试使用充气城堡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 doc,对我来说似乎没问题......

编译错误

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 个答案:

答案 0 :(得分:3)

您使用的是版本1.45,这是很旧的,当前版本是1.58。

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

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