BouncyCastle 错误:无法识别基于 ECDSA 的签名者中的密钥类型
我一直在使用 BouncyCastle 的加密库和 RSA 的加密库进行一些简单的测试。我正在做的是生成一个私钥/公钥对,如下所示:
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "JsafeJCE");
kpg.initialize(new ECGenParameterSpec("secp384r1"));
KeyPair kp = kpg.genKeyPair();
PrivateKey priv = kp.getPrivate();
PublicKey pub = kp.getPublic();
然后我像这样生成签名
Signature sig = Signature.getInstance("SHA384/ECDSA","BC");
,然后尝试签署私钥:
sig.initSign(priv);
所有这些都会给我带来错误:
java.security.InvalidKeyException:无法识别密钥输入基于 ECDSA 的签名者
当我 BC 和 JsafeJCE 时,我没有收到任何错误,一切都很好。如果两个提供商都是 BC,也适用。那么为什么我无法使用 BC 库对 JsafeJCE 生成的密钥进行签名?
I have been doing some simple testing with BouncyCastle's crypto library and RSA's crypto library. What I am doing is generating a private/public key pair like so:
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "JsafeJCE");
kpg.initialize(new ECGenParameterSpec("secp384r1"));
KeyPair kp = kpg.genKeyPair();
PrivateKey priv = kp.getPrivate();
PublicKey pub = kp.getPublic();
Then I generate the signature like so
Signature sig = Signature.getInstance("SHA384/ECDSA","BC");
and I try to sign the private key:
sig.initSign(priv);
All of this gets me the error:
java.security.InvalidKeyException: can't recognise key type in ECDSA based signer
When I BC and JsafeJCE, I get no error and everything is fine. Works also if both providers are BC. So why is it I can't sign the JsafeJCE generated key with the BC lib?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Bouncycastle 要求用于其签名实现的私钥必须是它自己的私钥之一。我不知道为什么您无论如何都会为不同的部件选择不同的提供商。
Bouncycastle requires that the private key used for its signing implementation must be one of its own. I don't know why you'd choose different providers for the various pieces in any event.
我通过以下步骤解决了同样的问题:
1)创建静态提供程序:
2)生成密钥对:
3)如果您想使用密钥签署某些内容:
它对我有用,希望也对您有用。
I solved the same issue by following the below steps:
1) Create static provider:
2) Generate keyPair:
3) If you want to sign something using key:
It worked for me, and will hopefully work for you as well.