skavinvarnan / Cross-Platform-AES

Simple cross-platform encryption and decryption using AES
MIT License
142 stars 69 forks source link

encryptPlainTextWithRandomIV in Android and decryptCipherTextWithRandomIV in php don't work #16

Closed TechNov closed 5 years ago

TechNov commented 5 years ago

Hello, I trying to encrypt test in Android Java and decrypt in php using encryptPlainTextWithRandomIV in Android and decryptCipherTextWithRandomIV in php. But php can't decrypt the crypted text from android. I use the same Key both.

--------------Android code-------------- String AES_CRYPT_KEY = "Awpj5scJh9gdeKBdnpl5df5d8sqPlfNe"; AESEncryption aesEncryption= new AESEncryption(); String text="2019/01/18 20:04:55#QNd7OpVZ4w56Z8VZ8j5HcHk7UdxinD#U_4752256_nsia#1234567890"; Log.d("AES crypt", aesEncryption.encryptPlainTextWithRandomIV(AES_CRYPT_KEY, text));

Android encryption result: jiAfm/9C+whU/EOG4MW52LNnBNQflM5Ajx2qSdncaL++tF2mpLl/oiPTuBwFCceftUAj9UoaEbE9HqYXVgh/ug== -------------PHP code -----------------

<?php 
 require '../libs/vendor/autoload.php';
$secretyKey = "Awpj5scJh9gdeKBdnpl5df5d8sqPlfNe";
$encryption = new \MrShan0\CryptoLib\CryptoLib();
$crypted="jiAfm/9C+whU/EOG4MW52LNnBNQflM5Ajx2qSdncaL++tF2mpLl/oiPTuBwFCceftUAj9UoaEbE9HqYXVgh/ug==";
$plainText = $encryption->decryptCipherTextWithRandomIV($crypted, $secretyKey);
echo 'Decrypted: ' . $plainText . PHP_EOL;

?>

// OUTPUT is Empty........... Decrypted:

Help please

skavinvarnan commented 5 years ago

@ahsankhatri can you take a look into this issue?

ahsankhatri commented 5 years ago

@TechNov I took your cipher and tried to decrypt with Android & PHP as well, it seems your cipher is not generated on AES/CBC/256. Give a try with file Android/ExampleActivity.kt in this repo first and try to decrypt in PHP. It'll work for sure as it work for me with the following:

Key: Awpj5scJh9gdeKBdnpl5df5d8sqPlfNe Cipher: mVuJdcakQTKQq4mO+iyBjQdo0Iyc5EybCZbQuDgMCtWtoBiCN4B9MI59WD+/w3B9bUO18EYUR8ab88/0D3NuIjiPOxSU6w04txa4P5g6u9lIhElnkNYHwub/kejIQdeB

FYI: Your cipher length should be 128 as mine if you're not using custom options to encrypt.

skavinvarnan commented 5 years ago

Closing issue due to inactivity