私钥和公钥不一样

发布于 2024-12-18 13:34:14 字数 558 浏览 2 评论 0原文

我想知道为什么当我使用此代码时私钥不同:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

复古式 2024-12-25 13:34:14

要从私钥获取公钥,您应该首先将私钥导出到证书中,然后从证书中导入(获取)公钥。

加载密钥库后,您可以编写如下 -

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文