Aeadbadtagexception While Decrypting My File Android Keystore Aes Cipher
I'm trying to Encrypt and Decrypt the String using AES Algorithm and GCM mode. My code is able to encrypt the string but I'm not able to decrypt the encoded data. Steps followed :
Solution 1:
Found the problem..
The issue is because the code encrypted the IV as well to start of the file, instead it should have been directly to fileoutputstream and not cipheroutputstream.
privatestaticvoidencrypt(Context context,String content, String fileName,Cipher cipher1)throws Exception {
...
try (FileOutputStreamfileOut= context.openFileOutput(fileName, Context.MODE_PRIVATE);
CipherOutputStreamcipherOut=newCipherOutputStream(fileOut, cipher)) {
fileOut.write(iv); // change is here
cipherOut.write(content.getBytes("UTF-8"));
cipherOut.flush();
}
Post a Comment for "Aeadbadtagexception While Decrypting My File Android Keystore Aes Cipher"