public static string ComputeHash(string source, string key = "%^&*AnTe")
{
    if (source == null)
    {
        return "";
    }
    string str = "abcdefghjklmnopqrstuvwxyz";
    if (source.Length < 0x1a)
    {
        source = source + str.Substring(source.Length);
    }
    byte[] bytes = Encoding.Unicode.GetBytes(source);
    int length = bytes.Length;
    if ((key == null) || (key.Length == 0))
    {
        key = "Encrypthejinhua";
    }
    byte[] buffer2 = Encoding.Unicode.GetBytes(key);
    byte num2 = Convert.ToByte(buffer2.Length);
    byte num3 = 2;
    byte index = 0;
    for (int i = 0; i < length; i++)
    {
        byte[] buffer3;
        IntPtr ptr;
        byte num6 = (byte) (buffer2[index] | num2);
        num6 = (byte) (num6 & num3);
        (buffer3 = bytes)[(int) (ptr = (IntPtr) i)] = (byte) (buffer3[(int) ptr] ^ num6);
        num3 = (byte) (num3 + 1);
        if (num3 > 0xfd)
        {
            num3 = 2;
        }
        index = (byte) (index + 1);
        if (index >= num2)
        {
            index = 0;
        }
    }
    return Convert.ToBase64String(bytes, 0, bytes.Length);

解决方案 »

  1.   

    function ComputeHash($source, $key = "%^&*AnTe") {
      if ($source == '') return "";
      $str = "abcdefghjklmnopqrstuvwxyz";
      if (strlen($source) < 0x1a) $source = $source . substr($str, strlen($source));
      $bytes = array_values(unpack('C*', iconv('utf-8', 'utf-16LE', $source)));
      $length = count($bytes);
      if ( strlen($key) == 0) $key = "Encrypthejinhua";
      $buffer2 = array_values(unpack('C*', iconv('utf-8', 'utf-16LE', $key)));
      $num2 = count($buffer2);//Convert.ToByte(buffer2.Length);
      $num3 = 2;
      $index = 0;
      for($i = 0; $i < $length; $i++) {
        $num6 = $buffer2[$index] | $num2;
        $num6 = $num6 & $num3;
        $bytes[$i] ^= $num6;
        $num3 = $num3 + 1;
        if ($num3 > 0xfd) $num3 = 2;
        $index = $index + 1;
        if ($index >= $num2) $index = 0;
      }
      return base64_encode(join('', array_map('chr', $bytes)));
    }C# 的 byte[] 并不是只读的
    所以把 bytes[i] = bytes[i] ^ num6);
    写作 
    byte[] buffer3;
    IntPtr ptr;
    (buffer3 = bytes)[(int) (ptr = (IntPtr) i)] = (byte) (buffer3[(int) ptr] ^ num6);
    是毫无道理的!
      

  2.   

    请允许我说藏话,版主太屌~很多.net 的方法 实在不知道是什么意思,被你解析完,瞬间通达