ryan14 Posted May 10, 2010 Share Posted May 10, 2010 is there a way to encrypt private messages using php? i know passwords can be encrypted using md5, but i have a custom made forum where users can send each other private messages and currently the messages are stored in plain text so I want to know how i can encrypt private messages. Quote Link to comment https://forums.phpfreaks.com/topic/201218-encrypt-private-messages/ Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 Anything can be encrypted, but what md5 is a one-way encryption (i.e. you can't decrypt it). You probably want some like base64. Ken Quote Link to comment https://forums.phpfreaks.com/topic/201218-encrypt-private-messages/#findComment-1055658 Share on other sites More sharing options...
teamatomic Posted May 10, 2010 Share Posted May 10, 2010 Sure, but md5 is not the way to go. Base64 should also be avoided, it is not encryption but rather encoding and anyone with any type of familiarity with it will recognize it and easily decode it. You need something a bit stronger. Try playing with this, its a blowfish encryption example and all you need to get going to implement something that will withstand even the NSA(at least for a while). You can also md5 the key and use it the same way you would a password for more security. $cc = 'it was the best of times...it was the worst of times...it was a psychedelic roller coaster'; $key = 'my secret key yek terces ym';// the stronger the better $iv = '12345678';// must be 8 bit length $cipher = mcrypt_module_open(MCRYPT_BLOWFISH,'','cbc',''); mcrypt_generic_init($cipher, $key, $iv); $encrypted = mcrypt_generic($cipher,$cc); mcrypt_generic_deinit($cipher); mcrypt_generic_init($cipher, $key, $iv); $decrypted = mdecrypt_generic($cipher,$encrypted); mcrypt_generic_deinit($cipher); echo "encrypted : ".$encrypted; echo "<br>"; $decrypted=rtrim($decrypted,"\0"); echo "decrypted : $decrypted"; HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/201218-encrypt-private-messages/#findComment-1055821 Share on other sites More sharing options...
Sudantha Posted May 10, 2010 Share Posted May 10, 2010 Just pass your sting to sha1($string); or md5($string); Quote Link to comment https://forums.phpfreaks.com/topic/201218-encrypt-private-messages/#findComment-1055930 Share on other sites More sharing options...
Adam Posted May 10, 2010 Share Posted May 10, 2010 Just pass your sting to sha1($string); or md5($string); Then how will the user read it later? Quote Link to comment https://forums.phpfreaks.com/topic/201218-encrypt-private-messages/#findComment-1055931 Share on other sites More sharing options...
Sudantha Posted May 10, 2010 Share Posted May 10, 2010 Just pass your sting to sha1($string); or md5($string); Then how will the user read it later? sorry actually i forgot that md5 and sha1 are one way encryption ! . anyways is there any way in php with two way encryption except for ur own algorithm Quote Link to comment https://forums.phpfreaks.com/topic/201218-encrypt-private-messages/#findComment-1055937 Share on other sites More sharing options...
Adam Posted May 10, 2010 Share Posted May 10, 2010 http://www.php.net/manual/en/refs.crypto.php Quote Link to comment https://forums.phpfreaks.com/topic/201218-encrypt-private-messages/#findComment-1055938 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.