将字节编码的密钥转回 Bouncy Castle 中的原始 ECPublicKey
在 Java 中,我有一个 ECDH 公钥,我将其作为字节数组发送。
一旦我收到字节数组,如何将其转回公钥?
我正在使用 Bouncy Castle,但 Java 解决方案也同样有用。
谢谢
In Java I have a ECDH public Key that I am sending as a byte array.
Once I have received the byte array how can I turn it back into a public key?
I am using Bouncy Castle but a Java solution would be just as useful.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您获得编码密钥时,假设您使用默认的“[your keyPair].getPublic().getEncoded()”方法,这将起作用。
When you got the encoded key, assuming you used the default "[your keyPair].getPublic().getEncoded()" method, this will work.
我发现@LaceCard 的上述解决方案对我不起作用。一般来说,这并不明显,但密码学中没有什么是明显的;)
注意:您需要适当地处理潜在的异常
I found the above solution by @LaceCard didn't work for me. In general this isn't obvious but then again nothing in cryptography is ;)
Note: you'll need to handle the potential exceptions appropriately
ECDH 密钥的原始字节如何格式化?你从哪里获得原始字节?
通常,使用适当的 *Spec 类将原始密钥材料转换为密钥,但 ECPublicKeySpec 和 DHPublicKeySpec 类不接受原始字节数组。
How are the raw bytes formatted for the ECDH key? Where are you getting the raw bytes?
Generally, one uses the appropriate *Spec class to turn raw key material into a Key but the ECPublicKeySpec and DHPublicKeySpec classes don't accept a raw byte array.