Forum Moderators: coopster

Message Too Old, No Replies

Mcrypt Generic Problems

PHP, Encryption, Problems, Mcrypt

         

starefossen

11:24 pm on Aug 5, 2008 (gmt 0)

10+ Year Member



Well I have these two functions

//Fusion Encrypt
function fusion_encrypt($text, $key) {
/* Open module, and create IV */
$td = mcrypt_module_open('des', '', '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);

/* Encrypt data */
mcrypt_generic_init($td, $key, $iv);
$encrypted = mcrypt_generic($td,$text);
mcrypt_generic_deinit($td);

/* Return data */
return $encrypted;
}

//Fusion Decrypt
function fusion_decrypt($text, $key) {
/* Open module, and create IV */
$td = mcrypt_module_open('des', '', '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);

$text = rtrim($text, "\0");

/* Decrypt data */
mcrypt_generic_init($td, $key, $iv);
$decrypted = mdecrypt_generic($td,$text);
mcrypt_generic_deinit($td);

/* Return data */
return $decrypted;
}

Which ecrypts a given string with a given key and decrypts a given string with a given key. Problem is, when using more words it is only decryptiong half of the encrypded text.

Is there anyone who have any knowledge with mcrypt? :)

Thanks in advance
Starefossen

eelixduppy

1:33 pm on Aug 8, 2008 (gmt 0)



Does this script output the full string but with only half of it decrypted or just half the text decrypted? Also, try to do the same things, but remove all your substr and trims and see if that fixes aything. At a quick glance, I don't see anything wrong.