Jump to content

Decryption function doing something weird with encoding


Speedysnail6

Recommended Posts

Hi. This is a function to decrypt text. Please do not worry about the masterkey, that is called upon from outside.

//Decryption Function
function decrypt($mprhase) {
    global $encryptionkey;
    $MASTERKEY = $encryptionkey;
    $td = mcrypt_module_open('tripledes', '', 'ecb', '');
    $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    mcrypt_generic_init($td, $MASTERKEY, $iv);
    $decrypted_value = mdecrypt_generic($td, base64_decode($mprhase));
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);
    return $decrypted_value;
}

Although this works normally, it does decrypt text with some weird encoding or something. I've tried decrypt() multiple times in an IF statement and was very confused why it does not work. It seems to look alike in code and in words when I echo it directly on a page, but when I tried putting the decrypt content in a textarea, and I get

Decrypted Text���

in the textarea. What is my decription function doing with the encoding or whatever, and please tell me how to correct it.

 

Thanks in advance and please tell me if I am not being clear enough.

Thanks! I used trim() and it worked.

New code is...

//Decryption Function
function decrypt($mprhase) {
    global $encryptionkey;
    $MASTERKEY = $encryptionkey;
    $td = mcrypt_module_open('tripledes', '', 'ecb', '');
    $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    mcrypt_generic_init($td, $MASTERKEY, $iv);
    $decrypted_value = mdecrypt_generic($td, base64_decode($mprhase));
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);
    return trim($decrypted_value);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.