PHP-implemented DES encryption and decryption instance code, phpdes encryption and decryption instance _ PHP Tutorial

Source: Internet
Author: User
PHP implements DES encryption and decryption instance code, and phpdes encrypts and decrypts instances. PHP-implemented DES encryption and decryption instance code. phpdes encryption and decryption instance this article describes the PHP-implemented DES encryption and decryption instance. For your reference, the code of the DES encryption and decryption instance implemented by php $ key PHP and the phpdes encryption and decryption instance are as follows:

This example describes the DES encryption and decryption instance implemented by PHP. We will share this with you for your reference. The details are as follows:

<? Php $ key = 'very impant Ant data'; function jiami ($ key, $ str) {/* Open module, and create IV */$ td = mcrypt_module_open ('Des ', '', 'ECB ',''); // $ td = mcrypt_module_open (MCRYPT_DES, '', MCRYPT_MODE_CBC,''); // $ td = mcrypt_module_open ('Des ', '', '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_RAND);/* I Nitialize encryption handle */if (mcrypt_generic_init ($ td, $ key, $ iv) ===- 1) {return FALSE ;} /* Encrypt data */$ c_t = mcrypt_generic ($ td, $ str);/* Clean up */mcrypt_generic_deinit ($ td); mcrypt_module_close ($ td ); return $ c_t;} function jiemi ($ key, $ str) {/* Open module, and create IV */$ td = mcrypt_module_open ('Des ','', 'ECB ', ''); // $ td = mcrypt_module_open (MCRYPT_DES,'', MCRYPT_MODE_CBC, ''); // $ Td = mcrypt_module_open ('Des ','', '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_RAND ); /* Initialize encryption handle */if (mcrypt_generic_init ($ td, $ key, $ iv) ===- 1) {return FALSE ;} /* Reinitialize buffers for decryption */$ p_t = mdecrypt_generic ($ td, $ str);/* Clean up */mcrypt_ge Neric_deinit ($ td); mcrypt_module_close ($ td); return trim ($ p_t);} $ str = 'Hello world! '; Echo 'key:'. $ key .'
'; Echo 'Str:'. $ str .'
'; $ Jiami = jiami ($ key, $ str); echo 'encryption:'. $ jiami .'
'{File_put_contents('jiamiqian.txt ', {str}{file_put_contents('jiamihou.txt', $ jiami); $ jiemi = jiemi ($ key, $ jiami); echo 'decryption: '. $ jiemi .'
';

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.