RSA公钥导出
这是我的代码
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
KeyPair myPair = kpg.generateKeyPair();
PrivateKey k = myPair.getPrivate();
System.out.print(k.serialVersionUID);
Cipher c = Cipher.getInstance("RSA");
c.init(Cipher.ENCRYPT_MODE, myPair.getPublic());
String myMessage = new String("Testing the message");
byte[] bytes = c.doFinal(myMessage.getBytes());
String tt = new String(bytes);
System.out.println(tt);
Cipher d = Cipher.getInstance("RSA");
d.init(Cipher.DECRYPT_MODE, myPair.getPrivate());
byte[] temp = d.doFinal(bytes);
String tst = new String(temp);
System.out.println(tst);
我的问题是如何获取公钥并将其存储在其他地方
Here is my code
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
KeyPair myPair = kpg.generateKeyPair();
PrivateKey k = myPair.getPrivate();
System.out.print(k.serialVersionUID);
Cipher c = Cipher.getInstance("RSA");
c.init(Cipher.ENCRYPT_MODE, myPair.getPublic());
String myMessage = new String("Testing the message");
byte[] bytes = c.doFinal(myMessage.getBytes());
String tt = new String(bytes);
System.out.println(tt);
Cipher d = Cipher.getInstance("RSA");
d.init(Cipher.DECRYPT_MODE, myPair.getPrivate());
byte[] temp = d.doFinal(bytes);
String tst = new String(temp);
System.out.println(tst);
My question is how can i get the public key and stored elsewhere
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 keyBytes 保存为二进制文件或将其存储在某个地方。
这样做可以重建密钥,
Save the keyBytes as binary file or store it somewhere.
Do this to reconstruct the key,