[英]Converting string to key and vice versa
I have problem with converting Key (security) to string and next convert it to that object. 我在将Key(安全性)转换为字符串并将其转换为该对象时遇到问题。 I have some errors:
我有一些错误:
java.lang.IllegalArgumentException: Illegal base64 character 20
and my code: 和我的代码:
KeyPairGenerator kpairg = KeyPairGenerator.getInstance("RSA");
kpairg.initialize(1024);
KeyPair kpair = kpairg.genKeyPair();
Key publicKey = kpair.getPublic();
// to String
String textFromKey = Base64.getEncoder().encodeToString(publicKey.getEncoded());
// to Key
byte[] byteKey = Base64.getDecoder().decode(textFromKey.getBytes());
X509EncodedKeySpec X509publicKey = new X509EncodedKeySpec(byteKey);
KeyFactory kf = KeyFactory.getInstance("RSA");
Key pubb = kf.generatePublic(X509publicKey);
textFromKey is sending to UDP server
textFromKey is a output from server if I want to use that key
I saw some answers in that website but anything help me. textFromKey is sending to UDP server
textFromKey is a output from server if I want to use that key
textFromKey is sending to UDP server
textFromKey is a output from server if I want to use that key
我会在该网站上看到一些答案,但是有什么可以帮助我的。 Could you look at this? 你能看看这个吗?
IDE told me that there is a problem: byte[] byteKey = Base64.getDecoder().decode(textFromKey.getBytes());
IDE告诉我有一个问题:
byte[] byteKey = Base64.getDecoder().decode(textFromKey.getBytes());
The issue is not clear from just the code. 仅从代码来看,问题还不清楚。 Can you try doing just
你能尝试做只是
X509EncodedKeySpec X509publicKey = new X509EncodedKeySpec(publicKey.getEncoded());
and get back? 再回来吗
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.