Reputation: 35
For example:
$text = "sample";
$salt = "sh54mdR";
I'd like to store $text value in the db as encrypted by using $salt value. result should be like that:
jkhdnewewjhjjhnd (it's just an example, so I want to hide $text value)
than id like to de-crypt "jkhdnewewjhjjhnd" to "sample" I can't use md5, sha etc. I'm looking for a way to store the value and than de-crypt it. do you know a PHP function for my request?
Upvotes: 2
Views: 194
Reputation: 99879
Look at the mcrypt functions.
Encrypt:
$key = "this is a secret key";
$input = "Let us meet at 9 o'clock at the secret place.";
$encrypted_data = mcrypt_ecb (MCRYPT_3DES, $key, $input, MCRYPT_ENCRYPT);
Decrypt:
$decrypted = mbcrypt_ecb(MCRYPT_3DES, $key, $encrypted_data, MCRYPT_DECRYPT);
See examples from http://us.php.net/manual/en/mcrypt.examples.php
Don't forget to use base64_encode() before storing in the database, unless the column accepts binary data.
Upvotes: 2
Reputation: 1425
use the Mcrypt library, it supports lots of ciphers (see the list here: http://www.php.net/manual/en/mcrypt.ciphers.php)
An example:
$text = "sample";
$salt = "sh54mdR";
$encrypted_data = mcrypt_ecb (MCRYPT_3DES, $salt, $text, MCRYPT_ENCRYPT);
Upvotes: 0