-1

i want to encrypt a text file. below is my code.But i am getting function error during run.

<?php

 $key = '123456';
 $plain_text = pkcs5_pad(file_get_contents('yourFile.txt'));

 /* Open module, and create IV */
 $td = mcrypt_module_open(MCRYPT_DES, '', MCRYPT_MODE_CBC, '');
 $key = substr($key, 0, mcrypt_enc_get_key_size($td));
 $iv_size = mcrypt_enc_get_iv_size($td);
 $iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);

 /* Initialize encryption handle */
 mcrypt_generic_init($td, $key, $iv);

/* Encrypt data */
$encrypted = mcrypt_generic($td, $plain_text);
mcrypt_generic_deinit($td);
file_put_contents('yourFile.txt.enc', $encrypted);
?>

i am getting below error..please help me to solve this.

Fatal error: Call to undefined function pkcs5_pad() in C:\xampp\htdocs\data\encrypt.php on line 4
Scott Arciszewski
  • 33,610
  • 16
  • 89
  • 206
bKashOST
  • 149
  • 4
  • 11
  • `pkcs5_pad` is not a standard function. Have you included it? – Artjom B. Apr 01 '16 at 14:28
  • i haven't included any function. i have just uncomment extension=php_mcrypt.dll in php.ini file and restarted xampp. can you please let me know the solution.. – bKashOST Apr 01 '16 at 14:41
  • Well, where did you get the idea that `pkcs5_pad` exists in PHP/mcrypt? Perhaps you should revisit the code you copied this from and include the missing function. Anyway, you shouldn't use mcrypt nowadays. It's abandonware. You should use something like php-defuse. – Artjom B. Apr 01 '16 at 14:48
  • Thanks for suggestion. can you please give any link for tutorial??? – bKashOST Apr 01 '16 at 14:56
  • http://stackoverflow.com/a/30159120/1816580 – Artjom B. Apr 01 '16 at 14:59

1 Answers1

0

You need to make sure that you have the mcrypt module installed, configured, and enabled before you can use the pkcs5_pad function. Installation and configuration will be different depending on your platform, so please see the documentation for assistance.

Mr. Llama
  • 20,202
  • 2
  • 62
  • 115