Hi,
I use the methods in PHP mcrypt module.

I have these two methods:

  // Decription Encryption
  public static function encrypt($string, $key){
    $cipher_alg = MCRYPT_RIJNDAEL_128;
    $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB),
MCRYPT_RAND);
    $encrypted_string = base64_encode(mcrypt_encrypt($cipher_alg, $key,
$string, MCRYPT_MODE_CBC, $iv));
    $iv_encode = base64_encode($iv);
    return $encrypted_string.'_'.$iv_encode;
  }


  public static function decrypt($encrypted_string, $key){
    $cipher_alg = MCRYPT_RIJNDAEL_128;
    list($encrypted_string, $iv) = explode('_', $encrypted_string);
    $decrypted_string = mcrypt_decrypt($cipher_alg, $key,
base64_decode($encrypted_string), MCRYPT_MODE_CBC, base64_decode($iv));
     $len = strlen($decrypted_string);
     $j = $len-1;
     while ($decrypted_string[$j] == "\0") $j--;
     $decrypted_string = substr($decrypted_string, 0, $j+1);
    return $decrypted_string;
  }


where $key is some fixed value stored in my app.yml file.

--Mohammad

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to