Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for an encrypt/decrypt AES example for Android

As I am new to encryption and particularly in Java/Android, I am struggling to find tutorials and code that work fine so that I can learn from them but the results.

As in this site: https://www.owasp.org/index.php/Using_the_Java_Cryptographic_Extensions

I couldn't find the problem that hit me with BASE64Encoder class, which seems to be inside package a sun.utils but I can find Base64 class but I could not tweak code so that it could work for me.

Similarly in this

android encryption/decryption with AES

The encryption is done in Bitmap Image I could not realize the same technique in normal text string.

Would someone supply a simple AES encryption/decryption example in Android just showing how to use key,message, encryption and decryption?

like image 336
erluxman Avatar asked Sep 14 '26 19:09

erluxman


1 Answers

I have used this for my project.

'com.scottyab:aescrypt:0.0.1'(ref: [enter link description here][1]

encryption:

String encryptedMsg = AESCrypt.encrypt(password, message);

decryption:

String messageAfterDecrypt = AESCrypt.decrypt(password, encryptedMsg);

if you are more concerned about security go with SHA1 or SHA256. Hope this helps.

Edit: In my case, i have to encrypt login password and send it to server over the network.

String userPassword = password.getText().toString();
try {
        encryptedMsg = AESCrypt.encrypt(userPassword, Config.secretlogin);
   } catch (GeneralSecurityException e) {
        e.printStackTrace();
   }

So in backend, i have decrypted the secure password with the key and in both sides i am using the same AES(Android and backend).

like image 86
GvSharma Avatar answered Sep 17 '26 07:09

GvSharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!