java 如何将私钥和公钥存储到 KeyStore 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11190509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to store Private Key and Public Key into KeyStore
提问by wayne_bai
All.I am working on an android project. I need to generate a RSA keypair then use them to communicate with others.I need to store the private key and public key in a secure place and I find KeyStore could be used.
All.I 正在开发一个 android 项目。我需要生成一个 RSA 密钥对,然后使用它们与其他人通信。我需要将私钥和公钥存储在一个安全的地方,我发现可以使用 KeyStore。
I see that KeyStore could store KeyStore.PrivateKeyEntry but it need a Certificate[] chain. I tried to create it but failed...
我看到 KeyStore 可以存储 KeyStore.PrivateKeyEntry 但它需要一个 Certificate[] 链。我试图创建它但失败了...
Is there anyone could paste some example code used to store private key and public key.
有没有人可以粘贴一些用于存储私钥和公钥的示例代码。
Thanks so much!
非常感谢!
采纳答案by sperumal
Like you said, in order to store the Private key into the keystore, you need the Private key (which you have) and the Certificate chain for the corresponding public key. What you have is just the public key, you need to obtain a certificate from an authority based on your public key. Yes, you can self-sign the certificate. But I don't think there is any built Java API to to create and self-sign a certificate programmatically.
就像您说的,为了将私钥存储到密钥库中,您需要私钥(您拥有)和相应公钥的证书链。您拥有的只是公钥,您需要根据您的公钥从权威机构获取证书。是的,您可以对证书进行自签名。但我不认为有任何内置的 Java API 来以编程方式创建和自签名证书。
There was similar discussion on this thread. The accepted solution describes storing private key and public key outside of keystore in a protected file.
在这个线程上有类似的讨论。已接受的解决方案描述了将私钥和公钥存储在密钥库之外的受保护文件中。
You can read more about Java Cryptography architecture here http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html
您可以在此处阅读有关 Java 加密体系结构的更多信息http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html
Hope this helps.
希望这可以帮助。