Looking for an encrypt/decrypt AES example for Android
Solution 1
The encryption and decryption process worked fine after: I replaced the byte array obtained from :
Bitmap
by byte array of message string
as instructed in
android encryption/decryption with AES
So even though my problem is not fully solved, this question should be marked as answered.
Solution 2
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).
erluxman
Open for remote jobs You can also hire me through upwork https://wwwerluxman.com https://www.upwork.com/freelancers/~01ca1c56b1ce85b4dd
Updated on June 28, 2022Comments
-
erluxman almost 2 years
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 findBase64
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?
-
erluxman almost 8 yearsi tried it but it says bad padding exception when i try to decrypt the data that i encrypted using AES encryption online 1.I encrypted the string using aesencryption.net 2.I encryted the same string using the library your mentioned. 3. the encrypted data are different 4.and android studio shows javax.crypto.BadPaddingException: error:1e06b065:Cipher functions:EVP_DecryptFinal_ex:BAD_DECRYPT exception while decrypting
-
GvSharma almost 8 yearslet me edit my answer with what i have tried in my case.
-
IgorGanapolsky almost 6 yearsIt is a deprecated repository
-
GvSharma almost 6 yearsglad you mentioned it, can you update here whats the latest version?