Hi,
Im using this code:
function encryptdata($data_input,$key){
$td = mcrypt_module_open('cast-256', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$encrypted_data = mcrypt_generic($td, $data_input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$encoded_64=base64_encode($encrypted_data);
return $encoded_64;
}
function decryptdata($encoded_64,$key){
$decoded_64=base64_decode($encoded_64);
$td = mcrypt_module_open('cast-256', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$decrypted_data = mdecrypt_generic($td, $decoded_64);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $decrypted_data;
}
To try to encrypt and decrypt some data, However the decrypted password has the first 2 letters missing. Whatever length string i put in its always the first 2 letters that go missing. I have tried multiple pieces of code over the internet with the exact same problem.
Example: (Original Password, Encrypted Password, Decrypted Password)
BEBw3nJ9rT y3CdmtNeTmhO3Jrq/00YOA== Bw3nJ9rT
Any help?
Thanks.
P.s Yes i am using the same key for the encryption and decryption.