Jump to content


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



Recommended Posts

I'm looking to keep the information in my database unreadable to the human eye. Pref. using a long password to 'decrypt' it and make it viewable to the admins in the admin panel. I know of some encryption methods that can do this such as Blowfish. However, I'm not sure where to go about using encryption in this manner with PHP.

Someone signs up > data is encrypted with a password and inserted into the mysql database > an admin logs into the admin panel and goes to the Pending page > the data is selected from the database, decrypted, and displayed.

I already have it working in plain text, so it's just the matter of sticking encryption on it.

Share this post

Link to post
Share on other sites
PHP extension: [url=http://us2.php.net/manual/en/ref.mcrypt.php]MyCrypt[/url]

example usage!


/* key to encode strings with (password) */

define ( 'SYS_KEY', 'my_super_encryption_key' );

/* encode function */

function encode_key ( $str )
$obj = mcrypt_create_iv ( mcrypt_get_iv_size ( MCRYPT_XTEA, MCRYPT_MODE_ECB ), MCRYPT_RAND );

return ( bin2hex ( gzcompress ( mcrypt_encrypt ( MCRYPT_XTEA, SYS_KEY, $str, MCRYPT_MODE_ECB, $obj ), 9 ) ) );

/* decode function */

function decode_key ( $str )
$str = @gzuncompress ( @pack ( 'H*', $str ) );

$obj = @mcrypt_create_iv ( @mcrypt_get_iv_size ( MCRYPT_XTEA, MCRYPT_MODE_ECB ), MCRYPT_RAND );

return ( @mcrypt_decrypt ( MCRYPT_XTEA, SYS_KEY, $str, MCRYPT_MODE_ECB, $obj ) );

// usage

$text = 'encrypt this string';

$encoded_string = encode_key ( $text );

echo "Encoded String: " . $encoded_string . "<br />";

echo "Decoded String: " . decode_key ( $encoded_string ) . "<br />";



bin2hex(), gzcompress() are used to make it safe for transport over any network connection (http, smtp, ... )


Share this post

Link to post
Share on other sites


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.