引用文章 QQ空间密码加密算法

53 篇文章 2 订阅
public static string EncyptMD5_3_16(string s)
  {
  MD5 mD = MD5.Create();
  byte[] bytes = Encoding.ASCII.GetBytes(s);
  byte[] buffer = mD.ComputeHash(bytes);
  byte[] buffer2 = mD.ComputeHash(buffer);
  byte[] array = mD.ComputeHash(buffer2);
  StringBuilder stringBuilder = new StringBuilder();
  byte[] array2 = array;
  for (int i = 0; i < array2.Length; i++)
  {
  byte b = array2[i];
  stringBuilder.Append(b.ToString("x").PadLeft(2, '0'));
  }
  return stringBuilder.ToString().ToUpper();
  }
  public static string smethod_0(string s)
  {
  MD5 mD = MD5.Create();
  byte[] bytes = Encoding.ASCII.GetBytes(s);
  byte[] array = mD.ComputeHash(bytes);
  StringBuilder stringBuilder = new StringBuilder();
  byte[] array2 = array;
  for (int i = 0; i < array2.Length; i++)
  {
  byte b = array2[i];
  stringBuilder.Append(b.ToString("x").PadLeft(2, '0'));
  }
  return stringBuilder.ToString().ToUpper();
  }
  public static byte[] EncyptMD5Bytes(string s)
  {
  MD5 mD = MD5.Create();
  byte[] bytes = Encoding.ASCII.GetBytes(s);
  return mD.ComputeHash(bytes);
  }
  public static string smethod_1(byte[] s)
  {
  MD5 mD = MD5.Create();
  byte[] array = mD.ComputeHash(s);
  StringBuilder stringBuilder = new StringBuilder();
  byte[] array2 = array;
  for (int i = 0; i < array2.Length; i++)
  {
  byte b = array2[i];
  stringBuilder.Append(b.ToString("x").PadLeft(2, '0'));
  }
  return stringBuilder.ToString().ToUpper();
  }
  public static string EncryptQQWebMd5(string s)
  {
  MD5 mD = MD5.Create();
  byte[] bytes = Encoding.ASCII.GetBytes(s);
  byte[] array = mD.ComputeHash(bytes);
  StringBuilder stringBuilder = new StringBuilder();
  byte[] array2 = array;
  for (int i = 0; i < array2.Length; i++)
  {
  byte b = array2[i];
  stringBuilder.Append("\\x");
  stringBuilder.Append(b.ToString("x2"));
  }
  return stringBuilder.ToString();
  }
  public static string EncryptOld(string password, string verifyCode)
  {
  return QQMd5.smethod_0(QQMd5.EncyptMD5_3_16(password) + verifyCode.ToUpper());
  }
  public static string Encrypt(string qq, string password, string verifyCode)
  {
  return QQMd5.Encrypt((long)Convert.ToInt32(qq), password, verifyCode);
  }
  public static string Encrypt(long qq, string password, string verifyCode)
  {
  ByteBuffer byteBuffer = new ByteBuffer();
  byteBuffer.Put(QQMd5.EncyptMD5Bytes(password));
  byteBuffer.PutInt(0);
  byteBuffer.PutInt((uint)qq);
  QQMd5.EncryptQQWebMd5(password);
  byte[] s = byteBuffer.ToByteArray();
  string str = QQMd5.smethod_1(s);
  return QQMd5.smethod_0(str + verifyCode.ToUpper());
  }

http://blog.csdn.net/red_angelx/article/details/1350095
我也是百度到的。虽然是JAVA的东西。C#也给实现了。。。c# byteBuffer 类。

  byteBuffer.Put(QQMd5.EncyptMD5Bytes(password));
  byteBuffer.PutInt(0);
  byteBuffer.PutInt((uint)qq);

这个地方要改成:

  byteBuffer.PushByteArray(EncyptMD5Bytes(password));
  byteBuffer.PushInt(0);
  byteBuffer.PushInt((uint)qq);


public static string Encrypt(long qq, string password, string verifyCode)

qq就是QQ号码


 

C#实现ByteBuffer类


using System;


namespace System.ByteBuffer
{
    /// <summary>
    /// 创建一个可变长的Byte数组方便Push数据和Pop数据
    /// 数组的最大长度为1024,超过会产生溢出
    /// 数组的最大长度由常量MAX_LENGTH设定
    /// 
    /// 注:由于实际需要,可能要从左到右取数据,所以这里
    /// 定义的Pop函数并不是先进后出的函数,而是从0开始.
    /// 
    /// @Author: Red_angelX
    /// </summary>
    class ByteBuffer
    {
        //数组的最大长度
        private const int MAX_LENGTH = 1024;
        
        //固定长度的中间数组
        private byte[] TEMP_BYTE_ARRAY = new byte[MAX_LENGTH];
        
        //当前数组长度
        private int CURRENT_LENGTH = 0;

        //当前Pop指针位置
        private int CURRENT_POSITION = 0;

        //最后返回数组
        private byte[] RETURN_ARRAY;

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ByteBuffer()
        {
            this.Initialize();
        }

        /// <summary>
        /// 重载的构造函数,用一个Byte数组来构造
        /// </summary>
        /// <param name="bytes">用于构造ByteBuffer的数组</param>
        public ByteBuffer(byte[] bytes)
        {
            this.Initialize();
            this.PushByteArray(bytes);
        }
    

        /// <summary>
        /// 获取当前ByteBuffer的长度
        /// </summary>
        public int Length
        {
            get
            {
                return CURRENT_LENGTH;
            }
        }

        /// <summary>
        /// 获取/设置当前出栈指针位置
        /// </summary>
        public int Position
        {
            get
            {
                return CURRENT_POSITION;
            }
            set
            {
                CURRENT_POSITION = value;
            }
        }

        /// <summary>
        /// 获取ByteBuffer所生成的数组
        /// 长度必须小于 [MAXSIZE]
        /// </summary>
        /// <returns>Byte[]</returns>
        public byte[] ToByteArray()
        {
            //分配大小
            RETURN_ARRAY = new byte[CURRENT_LENGTH];
            //调整指针
            Array.Copy(TEMP_BYTE_ARRAY, 0, RETURN_ARRAY, 0, CURRENT_LENGTH);
            return RETURN_ARRAY;
        }

        /// <summary>
        /// 初始化ByteBuffer的每一个元素,并把当前指针指向头一位
        /// </summary>
        public void Initialize()
        {
            TEMP_BYTE_ARRAY.Initialize();
            CURRENT_LENGTH = 0;
            CURRENT_POSITION = 0;
        }

        /// <summary>
        /// 向ByteBuffer压入一个字节
        /// </summary>
        /// <param name="by">一位字节</param>
        public void PushByte(byte by)
        {
            TEMP_BYTE_ARRAY[CURRENT_LENGTH++] = by;
        }

        /// <summary>
        /// 向ByteBuffer压入数组
        /// </summary>
        /// <param name="ByteArray">数组</param>
        public void PushByteArray(byte[] ByteArray)
        {
            //把自己CopyTo目标数组
            ByteArray.CopyTo(TEMP_BYTE_ARRAY, CURRENT_LENGTH);
            //调整长度
            CURRENT_LENGTH += ByteArray.Length;
        }

        /// <summary>
        /// 向ByteBuffer压入两字节的Short
        /// </summary>
        /// <param name="Num">2字节Short</param>
        public void PushUInt16(UInt16 Num)
        {
            TEMP_BYTE_ARRAY[CURRENT_LENGTH++] = (byte)(((Num & 0xff00) >> 8) & 0xff);
            TEMP_BYTE_ARRAY[CURRENT_LENGTH++] = (byte)((Num & 0x00ff) & 0xff);
        }

        /// <summary>
        /// 向ByteBuffer压入一个无符Int值
        /// </summary>
        /// <param name="Num">4字节UInt32</param>
        public void PushInt(UInt32 Num)
        {
            TEMP_BYTE_ARRAY[CURRENT_LENGTH++] = (byte)(((Num & 0xff000000) >> 24) & 0xff);
            TEMP_BYTE_ARRAY[CURRENT_LENGTH++] = (byte)(((Num & 0x00ff0000) >> 16) & 0xff);
            TEMP_BYTE_ARRAY[CURRENT_LENGTH++] = (byte)(((Num & 0x0000ff00) >> 8) & 0xff);
            TEMP_BYTE_ARRAY[CURRENT_LENGTH++] = (byte)((Num & 0x000000ff) & 0xff);
        }

        /// <summary>
        /// 向ByteBuffer压入一个Long值
        /// </summary>
        /// <param name="Num">4字节Long</param>
        public void PushLong(long Num)
        {
            TEMP_BYTE_ARRAY[CURRENT_LENGTH++] = (byte)(((Num & 0xff000000) >> 24) & 0xff);
            TEMP_BYTE_ARRAY[CURRENT_LENGTH++] = (byte)(((Num & 0x00ff0000) >> 16) & 0xff);
            TEMP_BYTE_ARRAY[CURRENT_LENGTH++] = (byte)(((Num & 0x0000ff00) >> 8) & 0xff);
            TEMP_BYTE_ARRAY[CURRENT_LENGTH++] = (byte)((Num & 0x000000ff) & 0xff);
        }

        /// <summary>
        /// 从ByteBuffer的当前位置弹出一个Byte,并提升一位
        /// </summary>
        /// <returns>1字节Byte</returns>
        public byte PopByte()
        {
            byte ret = TEMP_BYTE_ARRAY[CURRENT_POSITION++];
            return ret;
        }

        /// <summary>
        /// 从ByteBuffer的当前位置弹出一个Short,并提升两位
        /// </summary>
        /// <returns>2字节Short</returns>
        public UInt16 PopUInt16()
        {
            //溢出
            if (CURRENT_POSITION + 1 >= CURRENT_LENGTH)
            {
                return 0;
            }
            UInt16 ret = (UInt16)(TEMP_BYTE_ARRAY[CURRENT_POSITION] << 8 | TEMP_BYTE_ARRAY[CURRENT_POSITION + 1]);
            CURRENT_POSITION += 2;
            return ret;
        }

        /// <summary>
        /// 从ByteBuffer的当前位置弹出一个uint,并提升4位
        /// </summary>
        /// <returns>4字节UInt</returns>
        public uint PopUInt()
        {            
            if (CURRENT_POSITION + 3 >= CURRENT_LENGTH)
                return 0;
            uint ret = (uint)(TEMP_BYTE_ARRAY[CURRENT_POSITION] << 24 | TEMP_BYTE_ARRAY[CURRENT_POSITION + 1] << 16 | TEMP_BYTE_ARRAY[CURRENT_POSITION + 2] << 8 | TEMP_BYTE_ARRAY[CURRENT_POSITION + 3]);
            CURRENT_POSITION += 4;
            return ret;
        }

        /// <summary>
        /// 从ByteBuffer的当前位置弹出一个long,并提升4位
        /// </summary>
        /// <returns>4字节Long</returns>
        public long PopLong()
        {
            if (CURRENT_POSITION + 3 >= CURRENT_LENGTH)
                return 0;
            long ret = (long)(TEMP_BYTE_ARRAY[CURRENT_POSITION] << 24 | TEMP_BYTE_ARRAY[CURRENT_POSITION + 1] << 16 | TEMP_BYTE_ARRAY[CURRENT_POSITION + 2] << 8 | TEMP_BYTE_ARRAY[CURRENT_POSITION + 3]);
            CURRENT_POSITION += 4;
            return ret;
        }

        /// <summary>
        /// 从ByteBuffer的当前位置弹出长度为Length的Byte数组,提升Length位
        /// </summary>
        /// <param name="Length">数组长度</param>
        /// <returns>Length长度的byte数组</returns>
        public byte[] PopByteArray(int Length)
        {
            //溢出
            if (CURRENT_POSITION + Length >= CURRENT_LENGTH)
            {
                return new byte[0];
            }
            byte[] ret = new byte[Length];
            Array.Copy(TEMP_BYTE_ARRAY, CURRENT_POSITION, ret, 0, Length);
            //提升位置
            CURRENT_POSITION += Length;
            return ret;
        }

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值