GET登录求助 密码加密了

如题所述

第1个回答  2016-12-22
QQ空间现在采用的是动态加密,加密结果和验证码有密切关系,也就是说是:密码+算法+验证码在一起,加密算法如下: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 smethod_0(EncyptMD5_3_16(password) + verifyCode.ToUpper()); } public static string Encrypt(string qq, string password, string verifyCode) { return Encrypt((long)Convert.ToDouble(qq), password, verifyCode); } public class ByteBuffer { private byte[] byte_0; public Stream BaseStream; public ByteBuffer() { this.BaseStream = new MemoryStream(); this.byte_0 = new byte[16]; } public virtual long Seek(int offset, SeekOrigin origin) { return this.BaseStream.Seek((long)offset, origin); } public bool Peek() { return this.BaseStream.Position < this.BaseStream.Length; } public byte[] ToByteArray() { //long position = this.BaseStream.Position; //this.BaseStream.Position = 0L; //byte[] array = new byte[(int)((object)((IntPtr)this.BaseStream.Length))]; //this.BaseStream.Read(array, 0, array.Length); //this.BaseStream.Position = position; //return array; long position = this.BaseStream.Position; this.BaseStream.Position = 0L; byte[] buffer = new byte[this.BaseStream.Length]; this.BaseStream.Read(buffer, 0, buffer.Length); this.BaseStream.Position = position; return buffer; } public void Put(bool value) { this.byte_0[0] = value ? ((byte)1) : ((byte)0); this.BaseStream.Write(this.byte_0, 0, 1); } public void Put(byte value) { this.BaseStream.WriteByte(value); } public void Put(byte[] value) { if (value == null) { throw new ArgumentNullException("value"); } this.BaseStream.Write(value, 0, value.Length); } public void PutInt(int value) { this.PutInt((uint)value); } public void PutInt(uint value) { this.byte_0[0] = (byte)(value >> 24); this.byte_0[1] = (byte)(value >> 16); this.byte_0[2] = (byte)(value >> 8); this.byte_0[3] = (byte)value; this.BaseStream.Write(this.byte_0, 0, 4); } public void PutInt(int index, uint value) { int offset = (int)this.BaseStream.Position; this.Seek(index, SeekOrigin.Begin); this.PutInt(value); this.Seek(offset, SeekOrigin.Begin); } public byte Get() { return (byte)this.BaseStream.ReadByte(); } } public static string Encrypt(long qq, string password, string verifyCode) { ByteBuffer byteBuffer = new ByteBuffer(); byteBuffer.Put(EncyptMD5Bytes(password)); byteBuffer.PutInt(0); byteBuffer.PutInt((uint)qq); EncryptQQWebMd5(password); byte[] s = byteBuffer.ToByteArray(); string str = smethod_1(s); return smethod_0(str + verifyCode.ToUpper()); } 上面的加密算法,调用方法是:string str = Encrypt(QQ号, QQ密码, 验证码);加密后的密码会返回到str中,然后使用返回的密码进行登录。注:QQ空间登录是采用的GET而不是POST。
相似回答