includes/rijndael.php
changeset 345 4ccdfeee9a11
parent 286 b2f985e4cef3
child 348 87e08a6e4fec
equal deleted inserted replaced
344:be6c5fdd9203 345:4ccdfeee9a11
    93   127, 169,  25, 181,  74,  13,  45, 229, 122, 159, 147, 201, 156, 239, 160,
    93   127, 169,  25, 181,  74,  13,  45, 229, 122, 159, 147, 201, 156, 239, 160,
    94   224,  59,  77, 174,  42, 245, 176, 200, 235, 187,  60, 131,  83, 153,  97, 
    94   224,  59,  77, 174,  42, 245, 176, 200, 235, 187,  60, 131,  83, 153,  97, 
    95    23,  43,   4, 126, 186, 119, 214,  38, 225, 105,  20,  99,  85,  33,  12,
    95    23,  43,   4, 126, 186, 119, 214,  38, 225, 105,  20,  99,  85,  33,  12,
    96   125 );
    96   125 );
    97   
    97   
    98   function AESCrypt($ks = 128, $bs = 128, $debug = false)
       
    99   {
       
   100     $this->__construct($ks, $bs, $debug);
       
   101   }
       
   102   
       
   103   function __construct($ks = 128, $bs = 128, $debug = false)
    98   function __construct($ks = 128, $bs = 128, $debug = false)
   104   {
    99   {
   105     $this->keySizeInBits = $ks;
   100     $this->keySizeInBits = $ks;
   106     $this->blockSizeInBits = $bs;
   101     $this->blockSizeInBits = $bs;
   107     
   102     
  1026       while ($n >= 2147483648) $n -= 4294967296;
  1021       while ($n >= 2147483648) $n -= 4294967296;
  1027       while ($n <= -2147483649) $n += 4294967296;
  1022       while ($n <= -2147483649) $n += 4294967296;
  1028       return (int)$n;
  1023       return (int)$n;
  1029   }
  1024   }
  1030    
  1025    
  1031   function encrypt($str, $key) {
  1026   function encrypt($str, $key, $return_encoding = ENC_HEX) {
  1032       if ($str == "")
  1027       if ($str == "")
  1033       {
  1028       {
  1034           return "";
  1029           return "";
  1035       }
  1030       }
  1036       $v = $this->str2long($str, true);
  1031       $v = $this->str2long($str, true);
  1060           $z = $v[$n] = $this->int32($v[$n] + $mx);
  1055           $z = $v[$n] = $this->int32($v[$n] + $mx);
  1061       }
  1056       }
  1062       return $this->long2str($v, false);
  1057       return $this->long2str($v, false);
  1063   }
  1058   }
  1064    
  1059    
  1065   function decrypt($str, $key) {
  1060   function decrypt($str, $key, $encoding = ENC_HEX) {
  1066       if ($str == "") {
  1061       if ($str == "") {
  1067           return "";
  1062           return "";
  1068       }
  1063       }
  1069       $v = $this->str2long($str, false);
  1064       $v = $this->str2long($str, false);
  1070       $k = $this->str2long($key, false);
  1065       $k = $this->str2long($key, false);