Jump to content

PHP Encriptation question


fr@nkie

Recommended Posts

Hi. I'm new in php encriptation and I want to know what's wrong with my code.
How can I decrypt some data that I encrypt in another file?

<?php
   
   $key = "MyKey";
   $data = "Secret message";

   //encrypt
   $td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, ' ', MCRYPT_MODE_CFB, ' ');
   $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), 222);
   mcrypt_generic_init($td, $key, $iv);
   $encrypt_data = mcrypt_generic($td, $data);
   mcrypt_generic_deinit($td);
   mcrypt_module_close($td);
   
   //decrypt   
   $td1 = mcrypt_module_open(MCRYPT_RIJNDAEL_256, ' ', MCRYPT_MODE_CFB, ' ');
   $iv1 = mcrypt_create_iv (mcrypt_enc_get_iv_size($td1), 222);
   $key = substr($key, 0, mcrypt_enc_get_key_size($td1));
   mcrypt_generic_init($td1, $key, $iv1);
   $decrypt_data = mdecrypt_generic($td1, $encrypt_data);
   mcrypt_generic_deinit($td1);
   mcrypt_module_close($td1);
   
   //print
   echo "<p>Data encrypt: " . $encrypt_data . ".</p>\n";
   echo "<p>Data decrypt: " . $$decrypt_data . ".</p>\n";
?>
Link to comment
https://forums.phpfreaks.com/topic/33635-php-encriptation-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.