Android (Java) 中的 PublicKey 和 PrivateKey 构造函数
我想将我用应用程序生成的公钥和私钥保留在一个文件中,这样我就可以再次使用完全相同的密钥..但我意识到Android中没有任何用于PublicKey和PrivateKey对象的构造函数..所以当我可以保留它们并阅读它们时,我仍然无法在我的应用程序中重用它们..
有人可以告诉我如何完成它吗?
i want to keep the public and private keys I've generated with my application in a file so I could use the exact same keys another time.. but i realize that there isn't any constructor for PublicKey and PrivateKey object in Android.. so when I could keep them and read them, I still can't reuse them in my application..
could someone tell me how the way that it could be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PublicKey 和 PrivateKey 的 getEncoded 方法返回字节适合提供给 X509EncodedKeySpec 构造函数的数组(对于公钥)和 PKCS8EncodedKeySpec (对于私钥)。这些 KeySpec 反过来可以与适当的 KeyFactory 一起使用来重新生成私有密钥键。
The getEncoded methods of PublicKey and PrivateKey return byte arrays that should be suitable for supplying to the constructors for X509EncodedKeySpec (for the PublicKey) and PKCS8EncodedKeySpec (for the PrivateKey). These KeySpecs in turn may be used with the appropriate KeyFactory to regenerate the private keys.