PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/session/adodb-encrypt-md5.php

https://github.com/wojo/adodb-lite
PHP | 100 lines | 69 code | 14 blank | 17 comment | 11 complexity | 597fc62538f3d97a61c6f20765d88f6d MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. V4.65 22 July 2005 (c) 2000-2005 John Lim (jlim@natsoft.com.my). All rights reserved.
  4. Contributed by Ross Smith (adodb@netebb.com).
  5. Released under both BSD license and Lesser GPL library license.
  6. Whenever there is any discrepancy between the two licenses,
  7. the BSD license will take precedence.
  8. Set tabs to 4 for best viewing.
  9. */
  10. // security - hide paths
  11. if (!defined('ADODB_SESSION')) die();
  12. // Session Encryption by Ari Kuorikoski <ari.kuorikoski@finebyte.com>
  13. class MD5Crypt{
  14. function keyED($txt,$encrypt_key)
  15. {
  16. $encrypt_key = md5($encrypt_key);
  17. $ctr=0;
  18. $tmp = "";
  19. for ($i=0;$i<strlen($txt);$i++){
  20. if ($ctr==strlen($encrypt_key)) $ctr=0;
  21. $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
  22. $ctr++;
  23. }
  24. return $tmp;
  25. }
  26. function Encrypt($txt,$key)
  27. {
  28. srand((double)microtime()*1000000);
  29. $encrypt_key = md5(rand(0,32000));
  30. $ctr=0;
  31. $tmp = "";
  32. for ($i=0;$i<strlen($txt);$i++)
  33. {
  34. if ($ctr==strlen($encrypt_key)) $ctr=0;
  35. $tmp.= substr($encrypt_key,$ctr,1) .
  36. (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
  37. $ctr++;
  38. }
  39. return base64_encode($this->keyED($tmp,$key));
  40. }
  41. function Decrypt($txt,$key)
  42. {
  43. $txt = $this->keyED(base64_decode($txt),$key);
  44. $tmp = "";
  45. for ($i=0;$i<strlen($txt);$i++){
  46. $md5 = substr($txt,$i,1);
  47. $i++;
  48. $tmp.= (substr($txt,$i,1) ^ $md5);
  49. }
  50. return $tmp;
  51. }
  52. function RandPass()
  53. {
  54. $randomPassword = "";
  55. srand((double)microtime()*1000000);
  56. for($i=0;$i<8;$i++)
  57. {
  58. $randnumber = rand(48,120);
  59. while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96))
  60. {
  61. $randnumber = rand(48,120);
  62. }
  63. $randomPassword .= chr($randnumber);
  64. }
  65. return $randomPassword;
  66. }
  67. }
  68. /**
  69. */
  70. class ADODB_Encrypt_MD5 {
  71. /**
  72. */
  73. function write($data, $key) {
  74. $md5crypt =& new MD5Crypt();
  75. return $md5crypt->encrypt($data, $key);
  76. }
  77. /**
  78. */
  79. function read($data, $key) {
  80. $md5crypt =& new MD5Crypt();
  81. return $md5crypt->decrypt($data, $key);
  82. }
  83. }
  84. return 1;
  85. ?>