将字符串公钥转换为 RSA 公钥
我正在尝试将字符串公钥转换为带有模数和指数的公钥。 但为什么它不起作用呢?
这是我的代码
public void toPubKey(String filename,String sms) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, IOException{
byte[]keyBytes=sms.getBytes();
byte[]decode = Base64.encode(keyBytes, Base64.DEFAULT);
KeyFactory fact = KeyFactory.getInstance("RSA");
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(decode);
PublicKey pubKey2 = (PublicKey)fact.generatePublic(x509KeySpec);
saveToFile(filename,pubKey2);
我的代码有问题吗?
I'm trying to convert string public key to publickey with modulus and exponent.
but how come it doesnt works?
this is my code
public void toPubKey(String filename,String sms) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, IOException{
byte[]keyBytes=sms.getBytes();
byte[]decode = Base64.encode(keyBytes, Base64.DEFAULT);
KeyFactory fact = KeyFactory.getInstance("RSA");
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(decode);
PublicKey pubKey2 = (PublicKey)fact.generatePublic(x509KeySpec);
saveToFile(filename,pubKey2);
any problem with my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您的意思是您的代码是:
将
encode
更改为decode
。Perhaps you meant your code to be:
Change
encode
todecode
.