Quick Search:
 
 PHP Code: Reversible Encryption in PHP Jump to:  
Category: >> PHP Code >> Reversible Encryption in PHP  

<< lastnext >>

Snippet Name: Reversible Encryption in PHP

Description: Mcrypt is a PHP function that uses encryption algorithms. It can be used to encrypt and decrypt data.

Also see:
» Saving Remote Images With PHP
» More File Type Detection in PHP
» Send iCal Email Meeting Requests using...
» Checking Server Status with PHP
» Simple reversible encryption
» 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: February 19th, 2010

$string = "Mary had a little lamb.";
$key = "My Secret Key";
 
// Encryption Algorithm
$alg = MCRYPT_RIJNDAEL_256;
// Create the initialization vector for increased security.
$iv = mcrypt_create_iv(mcrypt_get_iv_size($alg, MCRYPT_MODE_ECB), MCRYPT_RAND);
 
// Output the original string
PRINT "The original string is: $string <p>";
 
// Encrypt $string
$encrypted_string = mcrypt_encrypt($alg, $key, $string, MCRYPT_MODE_CBC, $iv);
 
// Convert to hexadecimal and output to browser
 
PRINT "The encrypted string is: ".BIN2HEX($encrypted_string)."<p>";
$decrypted_string = mcrypt_decrypt($alg, $key, $encrypted_string, MCRYPT_MODE_CBC, $iv);
 
PRINT "The decrypted string is: $decrypted_string";
 


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