开发者

convert String publickey to RSA publickey

开发者 https://www.devze.com 2023-03-28 01:31 出处:网络
I\'m trying to convert string public key to publickey with modulus and exponent. but how come it doesnt works?

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, InvalidKeySpecEx开发者_如何学Pythonception, 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?


Perhaps you meant your code to be:

byte[]decode = Base64.decode(keyBytes, Base64.DEFAULT);

Change encode to decode.

0

精彩评论

暂无评论...
验证码 换一张
取 消