Jump to content


Photo

Encryption


  • Please log in to reply
1 reply to this topic

#1 esahp

esahp
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationUSA

Posted 30 September 2006 - 07:01 PM

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.

To obtain peace and quiet, get a Phoneless Cord.


#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 30 September 2006 - 07:13 PM

PHP extension: MyCrypt


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, ... )


me!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users