Hello all -- I'm an ASP guy trying to help out some folks with a PHP site, so forgive me if I say anything dumb that anyone who's passed PHP 101 should know.
We've got an application that takes in credit card numbers, encrypts them with mcrypt, and saves them to a mySQL database. Then in another page the numbers (and other appropriate user data) is retrieved and decrypted so that the numbers are visible again. Around 90% of those numbers come back decryped perfectly, but that other 10% does not -- I'm getting credit card numbers that look like: n_5a…iö¦6 8L2Œx -- sometimes the entire number looks like that, sometimes it's just the last 5-6 digits.
Here's what I'm working with:
function hide ($cardNumber) {
$key = 'key -- same key used in both encrypt & decrypt functions';
$td = mcrypt_module_open ('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
mcrypt_generic_init ($td, $key, $iv);
$encryptedData = mcrypt_generic ($td, $cardNumber);
mcrypt_generic_deinit ($td);
mcrypt_module_close ($td);
return $encryptedData;
} // end function hide
function show ($cardData) {
$key = 'again, same key as above';
$td = mcrypt_module_open ('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
mcrypt_generic_init ($td, $key, $iv);
$decryptedData = mdecrypt_generic ($td, $cardData);
mcrypt_generic_deinit ($td);
mcrypt_module_close ($td);
return $decryptedData;
} // end function show
Anyone have any thoughts?
by: i_m_aamirPosted on 2007-01-08 at 07:57:06ID: 18267622
Please have a look about,
base64_decode()
base64_encode()
BOL!