Jump to content

Encryption


esahp

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.

Basically:
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.
Link to comment
Share on other sites

PHP extension: [url=http://us2.php.net/manual/en/ref.mcrypt.php]MyCrypt[/url]


example usage!

[code=php:0]
<?

/* 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 />";

?>

[/code]

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


me!
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.