mervick / aes-everywhere

Aes Everywhere - Cross Language AES 256 Encryption Library (Bash, Powershell, C#, Dart, GoLang, Java, JavaScript, Lua, PHP, Python, Ruby, Swift)
Other
474 stars 169 forks source link

(Java) Base64 library requires high API level #6

Closed AzriDelta closed 5 years ago

AzriDelta commented 5 years ago

I noticed that the Base64 library requires API level 26 (Oreo), which is quite high. I am using my own phone (Nougat) to test my own app, so it doesn't work.

If I tried to change the library android.util.Base64, and modified codes from

return Base64.getEncoder().encodeToString(data);
final byte[] inBytes = Base64.getDecoder().decode(encrypted);
return Base64.encodeToString(data, Base64.DEFAULT);
final byte[] inBytes = Base64.decode(encrypted, Base64.DEFAULT);

On decryption, the error java.lang.IllegalArgumentException: Initial bytes from input do not match OpenSSL SALTED_MAGIC salt value. is thrown.

And of course even if it works, does it affect the libraries for other languages (especially Python, since I need to decrypt using Python)

mervick commented 5 years ago

I added class Base64 from Android package and created custom dev.mervick.android.Aes256 class.

Usage:

import dev.mervick.android.Aes256;

// encryption
String encrypted = Aes256.encrypt("TEXT", "PASSWORD");
System.out.println(encrypted);

// decryption
String decrypted = Aes256.decrypt(encrypted, "PASSWORD");
System.out.println(decrypted);
AzriDelta commented 5 years ago

that is fast.

About the error that I got, apparently it was a silly mistake of mine of trying to decrypt another string. Sorry about that.

Changing the library to android.util.Base64 does work for now. I will try to decrypt it using the python version.

mervick commented 5 years ago

Okay, then I close this