The php Encryption Class shared in this article is a php implementation class file that supports Chinese and English encryption and password decryption. If you need it, refer to it, but it is best to set the document encoding to UTF-8.
The following code is saved as the MD5Crypt. class. php file.
The Code is as follows: |
Copy code |
<? Php Class MD5Crypt { /** * Enter description here... * @ Param unknown_type $ str * @ Return string */ Public final static function mdsha ($ str ){ $ Code = substr (md5 ($ str), 10 ); $ Code. = substr (sha1 ($ str), 0, 28 ); $ Code. = substr (md5 ($ str), 0, 22 ); $ Code. = substr (sha1 ($ str), 16). md5 ($ str ); Return self: chkToken ()? $ Code: null; } /** * Enter description here... * @ Param unknown_type $ param */ Private final static function chkToken (){ Return true; } /** * Enter description here... * @ Param unknown_type $ txt * @ Param unknown_type $ encrypt_key * @ Return Ambigous <string, boolean> */ Private final static function keyED ($ txt, $ encrypt_key ){ $ Encrypt_key = md5 ($ encrypt_key ); $ Ctr = 0; $ Tmp = ""; For ($ I = 0; $ I <strlen ($ txt); $ I ++ ){ If ($ ctr = strlen ($ encrypt_key )) $ Ctr = 0; $ Tmp. = substr ($ txt, $ I, 1) ^ substr ($ encrypt_key, $ ctr, 1 ); $ Ctr ++; } Return $ tmp; } /** * Enter description here... * @ Param unknown_type $ txt * @ Param unknown_type $ key * @ Return string */ Public final static function Encrypt ($ txt, $ key ){ Srand (double) microtime () * 1000000 ); $ Encrypt_key = md5 (rand (0, 32000 )); $ Ctr = 0; $ Tmp = ""; For ($ I = 0; $ I <strlen ($ txt); $ I ++ ){ If ($ ctr = strlen ($ encrypt_key )) $ Ctr = 0; $ Tmp. = substr ($ encrypt_key, $ ctr, 1). (substr ($ txt, $ I, 1) ^ substr ($ encrypt_key, $ ctr, 1 )); $ Ctr ++; } $ _ Code = md5 ($ encrypt_key). base64_encode (self: keyED ($ tmp, $ key). md5 ($ encrypt_key. $ key ); Return self: chkToken ()? $ _ Code: null; } /** * Enter description here... * @ Param unknown_type $ txt * @ Param unknown_type $ key * @ Return Ambigous <string, boolean> */ Public final static function Decrypt ($ txt, $ key ){ $ Txt = self: keyED (base64_decode (substr ($ txt, 32,-32), $ key ); $ Tmp = ""; For ($ I = 0; $ I <strlen ($ txt); $ I ++ ){ $ Md5 = substr ($ txt, $ I, 1 ); $ I ++; $ Tmp. = (substr ($ txt, $ I, 1) ^ $ md5 ); } Return self: chkToken ()? $ Tmp: null; } /** * Enter description here... * @ Var unknown_type */ Private static $ _ key = 'lau '; } ?> |
Usage
The Code is as follows: |
Copy code |
<? Php // Code Start Define ('workspace ','. '. DIRECTORY_SEPARATOR ); Header ("Content-Type: text/html; charset = UTF-8 "); Include_once 'core/Library/MD5Crypt. class. php '; $ A = MD5Crypt: Encrypt ("A", 100 ); Echo "EnCode:". $ a, "<br/> "; Echo "DeCode:". MD5Crypt: Decrypt ($ a, 100 ); ?> |