RSA Encryption Decryption in Android

前端 未结 5 964
时光取名叫无心
时光取名叫无心 2020-12-12 11:12

I am implementing a demo for RSA Encryption and Decryption in Android. I can Perform Encryption very well, but In Decryption I get an Exception: >>java.security.

5条回答
  •  孤街浪徒
    2020-12-12 11:52

    when using RSAEcvypt method, its fill PublicKey and private key. And when your Decrypt your generated byte[], your publicKey and privateKey being NULL. Because of that you get this error.

    You should use your keys static;

    enter code here
    
    KeyPairGenerator kpg;
    KeyPair kp;
    static PublicKey publicKey;
    static PrivateKey privateKey;
    byte [] encryptedBytes,decryptedBytes;
    Cipher cipher,cipher1;
    String encrypted,decrypted;
    

提交回复
热议问题