mcrypt not fully decrypting?
| From: | Tyler Longren | Date: | Fri, 21 Feb 2003 21:45:04 +0000 |
| Subject: | mcrypt not fully decrypting? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-136563@lists.php.net to get a copy of this message | ||
Hi,
I'm going to start encrypting credit cards with the mcrypt functions. I
encrypted the credit cards like so:
$key = 'test';
$cc = "1234567890123456";
$td = mcrypt_module_open ('tripledes', '', 'ecb', '');
$key = substr ($key, 0, mcrypt_enc_get_key_size ($td));
$iv_size = mcrypt_enc_get_iv_size ($td);
$iv = mcrypt_create_iv ($iv_size, MCRYPT_RAND);
// Initialize encryption handle
if (mcrypt_generic_init ($td, $key, $iv) != -1) {
// Encrypt data
$ciphertext = mcrypt_generic ($td, $cc);
mcrypt_generic_deinit ($td);
// Reinitialize buffers for decryption
mcrypt_generic_init ($td, $key, $iv);
$plaintext = mdecrypt_generic ($td, $ciphertext);
// Clean up
mcrypt_generic_deinit ($td);
mcrypt_module_close ($td);
print "<font face=Arial size=2><b>Ciphertext:</b>
$ciphertext<Br>";
print "<b>Plaintext:</b> $plaintext</font>";
}
Sometimes, when I decrypt a cc it contains binary data...it's not fully
decrypted. There's some plaintext in it and there's also binary. Does
anyone know why this happens or how I can fix it?
Thanks,
Tyler