Quick Search:
 PHP Code: Simple reversible encryption Jump to:  
Category: >> PHP Code >> Simple reversible encryption  

<< lastnext >>

Snippet Name: Simple reversible encryption

Description: This is an example of encryption and decryption that uses the Mcrypt library.

Also see:
» Saving Remote Images With PHP
» More File Type Detection in PHP
» Send iCal Email Meeting Requests using...
» Checking Server Status with PHP
» Call a PHP function when clicking on a...
» Send Unicode Response From PHP
» Reversible Encryption in PHP
» Use htpasswd file with PHPscripts
» PHP and Oracle: Connect to database
» Server Stats via PHP
» FTP via PHP
» Online PHP Tester
» Email attachments with PHP mail()
» Basic PHP Calendar
» Check syntax of multiple PHP files all...
» Create mySQL table with PHP
» Create thumbnails with PHP
» PHP to JavaScript Array
» Pass vars to/from PHP
» PHP: connect to an Oracle database
» PHP to Oracle 8 DB abstraction
» Oracle with PHP
» Oracle with PHP

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

$string = "Some text to be encrypted";
$secret_key = "This is my SeCrEt key";
// Encryption Algorithm
$etype = MCRYPT_RIJNDAEL_256;
// Create the initialization vector for added security.
$iv = mcrypt_create_iv(mcrypt_get_iv_size($etype, MCRYPT_MODE_ECB), MCRYPT_RAND);
// Output original string
PRINT "Original string: $string <p>";
// Encrypt $string
$encrypted_string = mcrypt_encrypt($etype, $secret_key, $string, MCRYPT_MODE_CBC, $iv);
// Convert to hexadecimal and send to browser
PRINT "Encrypted string: ".BIN2HEX($encrypted_string)."<p>";
$decrypted_string = mcrypt_decrypt($etype, $secret_key, $encrypted_string, MCRYPT_MODE_CBC, $iv);
PRINT "Decrypted string is: $decrypted_string";

   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org