PHP implementation of DES encryption and decryption instance code, phpdes encryption decryption Instance _php tutorial

Source: Internet
Author: User
Tags getting started with php

PHP implementation of DES encryption and decryption instance code, phpdes encryption and decryption instances


The example of DES Encryption and decryption implemented by PHP is described in this paper. Share to everyone for your reference, as follows:

<?php$key = ' very important data '; function Jiami ($key, $STR) {/* Open module, and create IV */$td = Mcrypt_module_op  En (' 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;  }/* 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_generic_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. '
';

More about PHP related content readers can view the topic: "Summary of PHP encryption method," "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document tips summary (including word, excel,access,ppt), "PHP Date and Time usage summary", "PHP primer for Object-oriented programming", "PHP String Usage Summary", "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • The encryption and decryption method implemented by PHP combined with MD5
    • Analysis of PHP encryption and decryption example
    • SSL encryption decryption, authentication, signature method under PHP (very simple)
    • PHP encapsulated string encryption and decryption function
    • thinkphp Development (Message encryption and decryption)
    • A detailed explanation of PHP cryptographic decryption functions
    • PHP implementation of enhanced encryption decryption class instance
    • How to use PHP RSA encryption and decryption
    • PHP Encryption Decrypted String summary
    • An example analysis of PHP encryption and decryption class
    • Classic PHP Cryptographic decryption function authcode () fix code
    • PHP RSA encryption and decryption using the detailed
    • Base64_decode and Base64_encode Cryptographic decryption function instances in PHP

http://www.bkjia.com/PHPjc/1120004.html www.bkjia.com true http://www.bkjia.com/PHPjc/1120004.html techarticle PHP Implementation of DES encryption and decryption instance code, Phpdes encryption and decryption examples in this paper, the implementation of the PHP des encryption and decryption instance. Share to everyone for your reference, as follows: Php$key ...

  • Related Article

    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.