>  기사  >  백엔드 개발  >  중국어 PHP 암호화 및 복호화 클래스 지원

중국어 PHP 암호화 및 복호화 클래스 지원

WBOY
WBOY원래의
2016-07-25 09:08:471057검색
  1. /**
  2. * Copyright (c) 2011 - 01 XatuDream
  3. * XatuDream All Rights Reserved.
  4. * Support:185390516.qzone.qq.com
  5. * QQ:185390516
  6. * Author:Lau Version:1.01
  7. * Date:2010-08-12 09:28:32
  8. */
  9. ! defined ( 'WORKSPACE' ) && exit ( "Access Denied !" );
  10. class MD5Crypt {
  11. /**
  12. * Enter description here ...
  13. * @param unknown_type $str
  14. * @return string
  15. */
  16. public final static function mdsha($str) {
  17. $code = substr ( md5 ( $str ), 10 );
  18. $code .= substr ( sha1 ( $str ), 0, 28 );
  19. $code .= substr ( md5 ( $str ), 0, 22 );
  20. $code .= substr ( sha1 ( $str ), 16 ) . md5 ( $str );
  21. return self::chkToken () ? $code : null;
  22. }
  23. /**
  24. * Enter description here ...
  25. * @param unknown_type $param
  26. */
  27. private final static function chkToken() {
  28. return true;
  29. }
  30. /**
  31. * Enter description here ...
  32. * @param unknown_type $txt
  33. * @param unknown_type $encrypt_key
  34. * @return Ambigous
  35. */
  36. private final static function keyED($txt, $encrypt_key) {
  37. $encrypt_key = md5 ( $encrypt_key );
  38. $ctr = 0;
  39. $tmp = "";
  40. for($i = 0; $i < strlen ( $txt ); $i ) {
  41. if ($ctr == strlen ( $encrypt_key ))
  42. $ctr = 0;
  43. $tmp .= substr ( $txt, $i, 1 ) ^ substr ( $encrypt_key, $ctr, 1 );
  44. $ctr ;
  45. }
  46. return $tmp;
  47. }
  48. /**
  49. * Enter description here ...
  50. * @param unknown_type $txt
  51. * @param unknown_type $key
  52. * @return string
  53. */
  54. public final static function Encrypt($txt, $key) {
  55. srand ( ( double ) microtime () * 1000000 );
  56. $encrypt_key = md5 ( rand ( 0, 32000 ) );
  57. $ctr = 0;
  58. $tmp = "";
  59. for($i = 0; $i < strlen ( $txt ); $i ) {
  60. if ($ctr == strlen ( $encrypt_key ))
  61. $ctr = 0;
  62. $tmp .= substr ( $encrypt_key, $ctr, 1 ) . (substr ( $txt, $i, 1 ) ^ substr ( $encrypt_key, $ctr, 1 ));
  63. $ctr ;
  64. }
  65. $_code = md5 ( $encrypt_key ) . base64_encode ( self::keyED ( $tmp, $key ) ) . md5 ( $encrypt_key . $key );
  66. return self::chkToken () ? $_code : null;
  67. }
  68. /**
  69. * Enter description here ...
  70. * @param unknown_type $txt
  71. * @param unknown_type $key
  72. * @return Ambigous
  73. */
  74. public final static function Decrypt($txt, $key) {
  75. $txt = self::keyED ( base64_decode ( substr ( $txt, 32, - 32 ) ), $key );
  76. $tmp = "";
  77. for($i = 0; $i < strlen ( $txt ); $i ) {
  78. $md5 = substr ( $txt, $i, 1 );
  79. $i ;
  80. $tmp .= (substr ( $txt, $i, 1 ) ^ $md5);
  81. }
  82. return self::chkToken () ? $tmp : null;
  83. }
  84. /**
  85. * Enter description here ...
  86. * @var unknown_type
  87. */
  88. private static $_key = 'lau';
  89. }
  90. ?>
复制代码
  1. 使用方法:
  2. /**
  3. * Copyright (c) 2011 XatuDream
  4. * XatuDream All Rights Reserved.
  5. * Support:185390516.qzone.qq.com
  6. * QQ:185390516
  7. * Author:LoveCrystal Version:1.01
  8. * Date:2011-9-2 04:00:37
  9. */
  10. define ( 'WORKSPACE', '.' . DIRECTORY_SEPARATOR );
  11. header ( "Content-Type: text/html; charset=utf-8" );
  12. include_once 'Core/Library/MD5Crypt.class.php';
  13. $a = MD5Crypt::Encrypt ( "A", 100 );
  14. echo "EnCode:" . $a, "
    ";
  15. echo "DeCode:" . MD5Crypt::Decrypt ( $a, 100 );
  16. ?>
复制代码


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.