Monday, 21 May 2018

android cipher aes-256-cbc

below code works

to run it then you can use below code:

String key = "12345678901234567890123456789012"; //32-length
byte[] keyBytes = key.getBytes("UTF-8");
Random randomno = new Random();
byte[] ivBytes = new byte[16];
  String plainText; byte[] encryptedData;   //encryption: plainText = "xxx111xxx"; encryptedData = AES256Cipher.encrypt(ivBytes, keyBytes, plainText.getBytes("UTF-8"));
cipherData = AES256Cipher.decrypt(ivBytes, keyBytes, encryptedData); plainText = new String(cipherData, "UTF-8");

However, if you trying run this code on your android studio with junit, then you will find below error: Illegal key size or default parameters 

please check below link for detail:

No comments:

Post a comment