i am using the AES ALgo with 128 bit with CBC cipher mode encryption, below is the code:
$cc = 'my secret text';
$key = '3aa22e01c04c7059778c54d122b0273689fba00f4a166a66d15f7ba6a8ba8743';
$iv = '1234567890123456';
$length = strlen($cc);
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'','cbc','');
mcrypt_generic_init($cipher, $key, $iv);
$encrypted = base64_encode(mcrypt_generic($cipher,$cc));
mcrypt_generic_deinit($cipher);
mcrypt_generic_init($cipher, $key, $iv);
$decrypted = mdecrypt_generic($cipher,base64_decode($encrypted));
mcrypt_generic_deinit($cipher);
echo "encrypted: " . $encrypted;
echo "\n";
echo "decrypted: " . substr($decrypted, 0, $length) . "\n";
But this gives me a warning with output as :
Warning: mcrypt_generic_init(): Key size too large; supplied length: 64, max: 32 in /var/www/cipher.php on line 10 Warning: mcrypt_generic_init(): Key size too large; supplied length: 64, max: 32 in /var/www/cipher.php on line 14 encrypted: vM/XVYSjs/QApdCUEQ8bdQ== decrypted: my secret text
Now can someone guide me on why I am facing the size issue and how I can eradicate the issue of size without changing the key...