Jump to content

encrypt private messages


ryan14

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Just pass your sting to sha1($string); or md5($string);  8)

 

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  ;D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.