示例#1
0
        public string[] GetUserInfo()
        {
            string[]   sUserInfo = new string[2];
            Crypto3DES DesObject = new Crypto3DES();

            DesObject.Key = sDESKey;
            sUserInfo[0]  = DesObject.Decrypt3DES(Request.Cookies["UserInfo"]["account"].ToString());
            sUserInfo[1]  = DesObject.Decrypt3DES(Request.Cookies["UserInfo"]["pwd"].ToString());
            return(sUserInfo);
        }
示例#2
0
        public void SetUserInfo(string sAccount, string sMD5PassWord)
        {
            HttpCookie cookie = new HttpCookie("UserInfo");

            cookie.Expires = DateTime.Now.AddYears(1);
            Crypto3DES DesObject = new Crypto3DES();

            DesObject.Key = sDESKey;
            cookie.Values.Add("account", DesObject.Encrypt3DES(sAccount));
            cookie.Values.Add("pwd", DesObject.Encrypt3DES(sMD5PassWord));
            Response.AppendCookie(cookie);
        }
示例#3
0
        public int GetUserID()
        {
            Crypto3DES DesObject = new Crypto3DES();

            DesObject.Key = sDESKey;
            int iUserID = 0;

            if (Request.Cookies["UserID"] != null)
            {
                string sDesUserID = DesObject.Decrypt3DES(Request.Cookies["UserID"].Value);
                int.TryParse(sDesUserID, out iUserID);
            }
            return(iUserID);
        }
示例#4
0
        public void Crypto3DES_3Keys_Bundled_RandomIV_Test()
        {
            //Arrange
            byte[] keyBundle = { 8, 207, 159, 63, 78, 21, 2, 16, 158, 23, 64, 96, 57, 225, 36, 85, 49, 7, 210, 96, 13, 71, 62, 90 };

            CryptoSymmetric crypto           = new Crypto3DES(keyBundle);
            string          originalMessage  = "I love cryptography and TripleDES with three 64-bits keys";
            string          encryptedMessage = crypto.Encrypt(originalMessage);

            //Act
            string decryptedMessage = crypto.Decrypt(encryptedMessage);

            //Assert
            Assert.AreNotEqual(originalMessage, encryptedMessage);
            Assert.AreEqual(originalMessage, decryptedMessage);
        }
示例#5
0
        public void Crypto3DES_2Keys_RandomIV_Test()
        {
            //Arrange
            byte[] key1 = { 8, 207, 159, 63, 78, 21, 2, 16 };
            byte[] key2 = { 158, 23, 64, 96, 57, 225, 36, 85 };

            CryptoSymmetric crypto           = new Crypto3DES(key1, key2);
            string          originalMessage  = "I love cryptography and TripleDES with two 64-bits keys";
            string          encryptedMessage = crypto.Encrypt(originalMessage);

            //Act
            string decryptedMessage = crypto.Decrypt(encryptedMessage);

            //Assert
            Assert.AreNotEqual(originalMessage, encryptedMessage);
            Assert.AreEqual(originalMessage, decryptedMessage);
        }
示例#6
0
        public void Crypto3DES_2Keys_Bundled_FixedIV_Test()
        {
            //Arrange
            byte[] keyBundle = { 8, 207, 159, 63, 78, 21, 2, 16, 158, 23, 64, 96, 57, 225, 36, 85 };
            byte[] iv        = { 63, 208, 159, 46, 37, 77, 1, 59 };

            CryptoSymmetric crypto = new Crypto3DES(keyBundle);

            crypto.SetIV(iv);
            string originalMessage  = "I love cryptography and TripleDES with two 64-bits keys";
            string encryptedMessage = crypto.Encrypt(originalMessage);

            //Act
            string decryptedMessage = crypto.Decrypt(encryptedMessage);

            //Assert
            Assert.AreNotEqual(originalMessage, encryptedMessage);
            Assert.AreEqual(originalMessage, decryptedMessage);
        }
示例#7
0
        public void setcookies(string sAccount, int iUserID)
        {
            Crypto3DES DesObject = new Crypto3DES();

            DesObject.Key = sDESKey;
            Encoding enc = Encoding.GetEncoding("UTF-8");

            Response.Cookies["UserID"].Value      = DesObject.Encrypt3DES(iUserID.ToString());
            Response.Cookies["UserID"].Expires    = DateTime.Now.AddDays(1);
            Response.Cookies["Account"].Value     = HttpUtility.UrlEncode(sAccount, enc);
            Response.Cookies["Account"].Expires   = DateTime.Now.AddDays(1);
            Response.Cookies["logintime"].Value   = DateTime.Now.ToString();
            Response.Cookies["logintime"].Expires = DateTime.Now.AddDays(1);
            UserPoints upObject    = UserPointsBLL.UPointsSel(iUserID);
            int        iPoints     = upObject.Points;
            int        iGiftPoints = upObject.GiftPoints;

            SetPoints(iPoints + iGiftPoints);
            string sLoginInfo = GetUserLogin(iUserID);

            SetLogin(sLoginInfo);
        }