downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  

<Mcrypt ciphersMcrypt Functions>
Last updated: Thu, 26 Jun 2008

Examples

Mcrypt can be used to encrypt and decrypt using the above mentioned ciphers. If you linked against libmcrypt-2.2.x, the four important mcrypt commands (mcrypt_cfb(), mcrypt_cbc(), mcrypt_ecb(), and mcrypt_ofb()) can operate in both modes which are named MCRYPT_ENCRYPT and MCRYPT_DECRYPT, respectively.

Example #1 Encrypt an input value with TripleDES under 2.2.x in ECB mode

<?php
$key
= "this is a secret key";
$input = "Let us meet at 9 o'clock at the secret place.";

$encrypted_data = mcrypt_ecb (MCRYPT_3DES, $key, $input, MCRYPT_ENCRYPT);
?>
This example will give you the encrypted data as a string in $encrypted_data.

If you linked against libmcrypt 2.4.x or 2.5.x, these functions are still available, but it is recommended that you use the advanced functions.

Example #2 Encrypt an input value with TripleDES under 2.4.x and higher in ECB mode

<?php
   $key
= "this is a secret key";
  
$input = "Let us meet at 9 o'clock at the secret place.";

  
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
  
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
  
mcrypt_generic_init($td, $key, $iv);
  
$encrypted_data = mcrypt_generic($td, $input);
  
mcrypt_generic_deinit($td);
  
mcrypt_module_close($td);
?>
This example will give you the encrypted data as a string in $encrypted_data. For a full example see mcrypt_module_open().



add a noteadd a note User Contributed Notes
Examples
There are no user contributed notes for this page.




<Mcrypt ciphersMcrypt Functions>
Last updated: Thu, 26 Jun 2008
show source | credits | sitemap | contact | advertising | mirror sites
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://phpbuilder.com/
Last updated: Tue Nov 1 20:20:59 2005 EST
Columns / Articles | Tips / Quickies | News | News Linking and RSS Feeds | Shared Code Library
Mail Archives | Support / Discussion Forums | Get Started! Links | Contribute! | Docs