Speedysnail6 Posted October 14, 2013 Share Posted October 14, 2013 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. Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted October 15, 2013 Solution Share Posted October 15, 2013 see item C) in the following post - http://forums.phpfreaks.com/topic/281753-mysqli-error/?hl=%2Bdecrypt&do=findComment&comment=1447791 Quote Link to comment Share on other sites More sharing options...
Speedysnail6 Posted October 15, 2013 Author Share Posted October 15, 2013 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); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.