PHP Custom encryption method with encryption factor

Source: Internet
Author: User
Tags ord
Now PHP encryption methods have a lot of general, the general simple encryption method is directly MD5, but MD5 some simple password can also be decompile, so we now through the custom method to encrypt more secure.

Now is I collect and summarize some methods of PHP encryption method, share for everyone, for your reference.

Method One:

/*** Encrypt user's password * @param $password * @param $encrypt//Incoming encryption string, authentication when changing password * @return array/password*/function password ($ Password, $encrypt = ') {    $pwd = array ();    $pwd [' encrypt '] = $encrypt? $encrypt: Rand (1000,9999);     $pwd [' password '] = MD5 (MD5 (TRIM ($password)). $pwd [' encrypt ']);    Return $encrypt? $pwd [' Password ']: $pwd;}

Method Description: When we only pass in the password is, the method will return a cryptographic factor and a newly generated encryption password, and this encryption factor and password are randomly generated, each time is different.


Method Two:

/* * RC4 encryption Algorithm * $PWD key * $data data to be encrypted *  //$pwd key $data need to encrypt string function RC4 ($pwd, $data) {     $key [] = "";     $box [] = "";     $pwd _length = strlen ($pwd);     $data _length = strlen ($data);     for ($i = 0; $i < $i + +) {         $key [$i] = Ord ($pwd [$i% $pwd _length]);         $box [$i] = $i;     }     for ($j = $i = 0; $i < $i + +) {         $j = ($j + $box [$i] + $key [$i])%;         $tmp = $box [$i];         $box [$i] = $box [$j];         $box [$j] = $tmp;     }     for ($a = $j = $i = 0; $i < $data _length; $i + +) {         $a = ($a + 1)%;         $j = ($j + $box [$a])%;         $tmp = $box [$a];         $box [$a] = $box [$j];         $box [$j] = $tmp;         $k = $box [(($box [$a] + $box [$j])];         $cipher. = Chr (ord ($data [$i]) ^ $k);     }     return $cipher; }

Method Three:

/** +-----------------------------------------------------* Mcrypt Encrypt/decrypt * @param string $date the data to encrypt and decrypt * @param string $mode encode default to encrypt/decode for decryption * @return String * @author zxing@97md.net Mon Sep 22:59:28 CST +-------------------- ---------------------------------* @example */function Zxingcrypt ($date, $mode = ' encode ') {$key = MD5 (' zxing ');//MD     5 Hashishen into a key, note that the encryption and decryption keys must be unified if ($mode = = ' decode ') {$date = Base64_decode ($date); } if (Function_exists (' Mcrypt_create_iv ')) {$iv _size = mcrypt_get_iv_size (mcrypt_rijndael_256, MCRYPT_MODE_ECB         );     $iv = Mcrypt_create_iv ($iv _size, Mcrypt_rand); } if (Isset ($iv) && $mode = = ' encode ') {$passcrypt = Mcrypt_encrypt (mcrypt_rijndael_256, $key, $date,     MCRYPT_MODE_ECB, $IV); }elseif (Isset ($iv) && $mode = = ' decode ') {$passcrypt = Mcrypt_decrypt (mcrypt_rijndael_256, $key, $date, M     CRYPT_MODE_ECB, $IV); } if ($mode = = ' encode ') {$passcrypt = base64_Encode ($passcrypt); } return $passcrypt; }
  • 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.