Example #1
0
        /// <summary>
        /// Validates client agains PTF database
        /// </summary>
        /// <param name="key"></param>
        /// <param name="countryId"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="encryptedPassword"></param>
        /// <returns></returns>
        public static bool ValidateUser(DataPair <string, string> key, int countryId, string userName, string password,
                                        ref string encryptedPassword)
        {
            List <DbPasswordInfo> psw = MSSQL.ExecuteReader <DbPasswordInfo>(ConnectionStringPft,
                                                                             CommandType.StoredProcedure, "GetUserLoginDetail",
                                                                             new SqlParameter("@CountryId", countryId),
                                                                             new SqlParameter("@UserName", userName)
                                                                             );

            if (psw.Count == 0)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(psw[0].Salt))
            {
                return(psw[0].EncryptedPassword == password);
            }
            else
            {
                RijndaelCryptography rc = new RijndaelCryptography();
                rc.Key = Encoding.ASCII.GetBytes(key.Key);
                rc.IV  = Encoding.ASCII.GetBytes(key.Value);
                rc.Encrypt(password + psw[0].Salt);
                encryptedPassword = HttpUtility.UrlEncode(Convert.ToBase64String(rc.Encrypted));
                return(psw[0].EncryptedPassword == encryptedPassword);
            }
        }
Example #2
0
        public void TestRijndaelCrypto()
        {
            var crypto = new RijndaelCryptography();

            const string originalString = "Rijndael cryptography";
            var cryptoString = crypto.Encrypt(originalString);
            var decryptString = crypto.Decrypt(cryptoString);

            Assert.AreEqual(originalString, decryptString);
        }
Example #3
0
        /// <summary>
        /// Encode Cookie values
        /// </summary>
        /// <param name="encryptCookie">The encrypt cookie.</param>
        /// <returns></returns>
        private static HttpCookie EncryptCookie(HttpCookie encryptCookie)
        {
            HttpCookie cookie = new HttpCookie(encryptCookie.Name)
            {
                Value  = RijndaelCryptography.Encrypt(encryptCookie.Value, defaultKey),
                Domain = string.Format(".{0}", HttpContext.Current.Request.Url.Host)
            };

            return(cookie);
        }
Example #4
0
        public static string Encript(this string value, string key = null, string vector = null)
        {
            var cripto = new RijndaelCryptography();

            if (key != null && vector != null)
            {
                cripto.Key = ASCIIEncoding.Default.GetBytes(key);
                cripto.IV  = ASCIIEncoding.Default.GetBytes(vector);
            }
            var buffer = cripto.Encrypt(value);
            var result = Convert.ToBase64String(buffer);

            return(result.TrimSafe('\0'));
        }
Example #5
0
        /// <summary>
        /// Generates the user token.
        /// </summary>
        /// <param name="serviceKey">The service key.</param>
        /// <returns></returns>
        public string GenerateUserToken(Guid serviceKey)
        {
            bool   isValidUser    = IsValidUser(serviceKey);
            string encryptedToken = string.Empty;

            if (isValidUser)
            {
                //Add 5 hours to the current UTC
                DateTime time = DateTime.UtcNow.AddHours(5);

                //concate and encrypt the datetime and service key
                string unencryptedToken = time.Ticks + "|" + serviceKey;
                encryptedToken = RijndaelCryptography.Encrypt(unencryptedToken);
            }

            return(encryptedToken);
        }
        /// <summary>
        /// Encrypts the specified plain text.
        /// </summary>
        /// <param name="plainText">The plain text.</param>
        /// <returns></returns>
        public string Encrypt(string plainText)
        {
            string encryptText = RijndaelCryptography.Encrypt(plainText);

            return(encryptText);
        }