note 43872 added to function.mcrypt-encrypt
| From: | andrewcare at execulink dot com | Date: | Tue, 06 Jul 2004 23:45:46 +0000 |
| Subject: | note 43872 added to function.mcrypt-encrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72801@lists.php.net to get a copy of this message | ||
Plaintext encryption:
<?
$data = "Plaintext"; // Data to encrypt
(http://www.ciphersbyritter.com/glossary.htm#Encryption)
$key = "Secret"; // Encryption key (http://www.ciphersbyritter.com/glossary.htm#Key)
$td = MCRYPT_RIJNDAEL_256; // Encryption cipher (http://www.ciphersbyritter.com/glossary.htm#Cipher)
$iv_size = mcrypt_get_iv_size($td, MCRYPT_MODE_ECB); // Dependant on cipher/mode combination
(http://www.php.net/manual/en/function.mcrypt-get-iv-size.php)
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); // Creates an IV
(http://www.ciphersbyritter.com/glossary.htm#IV)
echo "Original data: $data<br />";
$encrypted_data = mcrypt_encrypt($td, $key, $data, MCRYPT_MODE_CBC, $iv); // Encrypts data
(http://www.php.net/manual/en/function.mcrypt-encrypt.php)
echo "Encrypted data: " . bin2hex($encrypted_data) /* bin2hex to compensate for random
character values */ . "<br />";
$data = mcrypt_decrypt($td, $key, $encrypted_data, MCRYPT_MODE_CBC, $iv); // Decrypts data
(http://www.php.net/manual/en/function.mcrypt-decrypt.php)
echo "Decrypted data: $data<br />";
?>
----
Manual Page -- http://www.php.net/manual/en/function.mcrypt-encrypt.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43872
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43872&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43872&report=yes
Search -- http://master.php.net/manage/user-notes.php