I'm trying to send data from my Android application to my Apache2 server running PHP 5.5 while having AES-128 encryption/decryption on both sides.
The weird thing is when I run the java code on Eclipse to encrypt the data (as a test) and take the encrypted result to decrypt it using PHP on Netbeans, it works just fine. Transferring the code to Android also gives the same encrypted results, but the decryption function on the server doesn't give back any results, it just gives a null, I'm using the exact same code I used on Netbeans which worked.
Here's the code
if(isset($_POST['param']))
{
$param = $_POST['param'];
$param=decrypt($param, "57238004e784498bbc2f8bf984565090");
}
else
echo "No post Request Received";
function decrypt($encrypted, $key) {
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, hex2bin($key),hex2bin($encrypted), MCRYPT_MODE_ECB);
echo $decrypted;
$padSize = ord(substr($decrypted, -1));
return substr($decrypted, 0, $padSize*-1);
}
echo $decrypted gives a null and the return as well.
Example: Cipher: 269B3F5A2208C533AACB51243CFB9CFB Decrypted to: 28
Anybody know what the problem might be?
var_dump($decrypted). if it's boolean false, then it didn't decrypt at all.