Below are the two functions i am using to encrypt/decrypt credit card #'s
For some reason it's not decrypting it correctly from mysql. I'm thinking i have the stored data type wrong or soemthing because if i run decryptCC("a24116e799c93d562656ab8fb7c21b5eb4afd37bcf933978c19459145ed55d34")
That will out put the correct cc number 411111111111 However when i decrypt the mysql field where is a24116e799c93d562656ab8fb7c21b5eb4afd37bcf933978c19459145ed55d34 present in the same file with the same decrypt function i get the out put of "8:šœ–“!‰ÅÚºv" not 411111111111 Any ideas? I've been looking at this for hours and i'm clueless I'm doing the same thing in another php file where decrypting and works fine. BTW i'm using mysql_feth_array when fetching the data. Thanks in advance
<?function hex2bin($data)
{
$len = strlen($data);
return pack("H" . $len, $data);
}
function encryptCC($theString){
global $key;
$cipher_alg = MCRYPT_RIJNDAEL_128;
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND);
$encrypted_string = mcrypt_encrypt($cipher_alg, $key, $theString, MCRYPT_MODE_CBC,$iv);
return bin2hex($iv) . bin2hex($encrypted_string);
}
function decryptCC($theString){
global $key;
$iv=substr($theString,0,32);
$theStringwoiv=substr($theString,32);
$cipher_alg = MCRYPT_RIJNDAEL_128;
$theStringBin = hex2bin($theStringwoiv);
return mcrypt_decrypt($cipher_alg, $key, $theStringBin, MCRYPT_MODE_CBC,hex2bin($iv));
}
?>