Beispiel #1
0
 // rc5 加密后大小不会变化的
 static public bool RC5_ECB_Symmetry_Encode_Byte(byte[] encryptByte, uint startPos, uint inLen, ref byte[] outBytes, RC5_32_KEY rgbKey, CryptContext cryptContext)
 {
     try
     {
         RC5.RC5_32_ecb_encrypt_one(encryptByte, startPos, inLen, ref outBytes, rgbKey, RC5.RC5_ENCRYPT, cryptContext);
         return(true);
     }
     catch
     {
         Ctx.m_instance.m_logSys.error("RC5_ECB_Symmetry_Encode_Byte error");
         return(false);
     }
 }
Beispiel #2
0
        protected void testRc5()
        {
            string testStr = "asdfasdf5";

            //byte[] inBytes = System.Text.Encoding.UTF8.GetBytes(testStr);
            byte[] inBytes  = { 0x3f, 0x79, 0xd5, 0xe2, 0x4a, 0x8c, 0xb6, 0xc1, 0x3f, 0x79, 0xd5, 0xe2, 0x4a, 0x8c, 0xb6, 0xc1 };
            byte[] outBytes = new byte[8];
            uint   inSize   = (uint)inBytes.Length;

            RC5_32_KEY rc5Key = new RC5_32_KEY();                             // RC5 key

            RC5.RC5_32_set_key(rc5Key, 16, Crypt.RC5_KEY, RC5.RC5_12_ROUNDS); // 生成秘钥

            CryptContext cryptContext = new CryptContext();

            Crypt.encryptData(inBytes, 0, 16, ref outBytes, cryptContext);
            Crypt.decryptData(outBytes, 0, 16, ref inBytes, cryptContext);
            testStr = System.Text.Encoding.Default.GetString(inBytes);
        }
Beispiel #3
0
        public static void Handle(byte[] Data, SocketClient Client)
        {
            Client.Crypto = new Cryptographer();
            Client.Crypto.Decrypt(ref Data);
            ushort PacketID = BitConverter.ToUInt16(Data, 2);

            if (PacketID == 1051)
            {
                string Account   = System.Text.ASCIIEncoding.ASCII.GetString(Data, 4, 16).Replace("\0", "");
                byte[] PassBytes = new byte[16];
                Buffer.BlockCopy(Data, 20, PassBytes, 0, 16);
                string    Password = RC5.Decrypt(PassBytes);
                DataTable DT       = Program.AccountDB.GetDataTable("SELECT `uid`, `type` FROM `userinfo` WHERE `username`='" + Account + "' AND `password`='" + Password + "'");
                if (DT.Rows.Count == 1)
                {
                    DataRow           dr       = DT.Rows[0];
                    uint              UID      = Convert.ToUInt32(dr.ItemArray[0]);
                    Enums.AccountType AcctType = (Enums.AccountType)Convert.ToByte(dr.ItemArray[1]);
                    if (AcctType == Enums.AccountType.BannedAccount)
                    {
                        Client.Send(Packets.ToSend.AuthResponse(Enums.AuthResponseType.Banned, UID));
                    }
                    else
                    {
                        string date = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
                        Program.AccountDB.ExecuteNonQuery("INSERT INTO `login_tokens` (`PlayerUID`, `Date`) VALUES ('" + UID + "', '" + date + "')");
                        Client.Send(Packets.ToSend.AuthResponse(Enums.AuthResponseType.Successful, UID));
                    }
                }
                else
                {
                    Client.Send(Packets.ToSend.AuthResponse(Enums.AuthResponseType.WrongPass, 0));
                }
            }
            Client.Disconnect();
        }
Beispiel #4
0
 public CryptContext()
 {
     m_cryptKeyArr[(int)CryptAlgorithm.RC5] = new RC5_32_KEY();
     m_cryptKeyArr[(int)CryptAlgorithm.DES] = new DES_key_schedule();
     RC5.RC5_32_set_key(m_cryptKeyArr[(int)CryptAlgorithm.RC5] as RC5_32_KEY, 16, Crypt.RC5_KEY, RC5.RC5_12_ROUNDS);     // 生成秘钥
 }