私钥和公钥不一样
我想知道为什么当我使用此代码时私钥不同:
java.security.KeyStore keyStoreFile = java.security.KeyStore.getInstance("PKCS12");
keyStoreFile.load(new FileInputStream("keyStore.pfx"),"password".toCharArray());
PrivateKey privateKey = (PrivateKey) keyStoreFile.getKey("alias","password".toCharArray());
String temp = new String(Base64.encodeBase64(privateKey.getEncoded()));
System.out.println(temp);
当我使用相同的密钥库将导出私钥与 keytool-iui.jnlp 一起使用时?
我认为这是代码错误,因为它在单行中生成私钥。
任何人都可以建议我该怎么做,因为我需要获取公钥并将其传递给其他程序员。但是公钥也出现在单行中,并且它是不正确的。 请帮忙!
I was wondering why private key is different when I use this code:
java.security.KeyStore keyStoreFile = java.security.KeyStore.getInstance("PKCS12");
keyStoreFile.load(new FileInputStream("keyStore.pfx"),"password".toCharArray());
PrivateKey privateKey = (PrivateKey) keyStoreFile.getKey("alias","password".toCharArray());
String temp = new String(Base64.encodeBase64(privateKey.getEncoded()));
System.out.println(temp);
and when I use export private key with keytool-iui.jnlp using the same keystore?
I think this is the code wrong as it produce private key in single line.
Can anyone suggest me what to do as I need to get public key and to pass it to other programmers. But public key gets in single line as well and it's incorrect.
Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要从私钥获取公钥,您应该首先将私钥导出到证书中,然后从证书中导入(获取)公钥。
加载密钥库后,您可以编写如下 -
Certificate crt = keyStoreFile.getCertificate("aliasOfPrivateKey");
公钥 publicKey = crt.getPublicKey();
然后从publicKey中获取编码后的字符串。
要了解有关生成私钥-公钥对的更多信息,请参阅以下内容 -
http://technologytriumph.blogspot.in/2012 /10/steps-to-generate-public-priavet-key.html
To get public key from private key, you should first export private key into certificate and then from the certificate you have to import (get) public key.
After loading the keystore you can write as follows -
Certificate crt = keyStoreFile.getCertificate("aliasOfPrivateKey");
PublicKey publicKey = crt.getPublicKey();
Then get the encoded string from publicKey.
To read more about generating private - public key pair please refer following -
http://technologytriumph.blogspot.in/2012/10/steps-to-generate-public-priavet-key.html