Exemple #1
0
        /// <summary>
        /// 加盐算法(私有)
        /// </summary>
        /// <param name="saltValue">盐</param>
        /// <param name="unsaltedText">加密字符</param>
        /// <returns>byte[]</returns>
        private static byte[] CreateSaltedText(byte[] saltValue, byte[] unsaltedText)
        {
            try
            {
                byte[] rawSalted = new byte[unsaltedText.Length + saltValue.Length];//加盐
                saltValue.CopyTo(rawSalted, 0);
                unsaltedText.CopyTo(rawSalted, saltValue.Length);

                byte[] saltedText = new SHA1CryptoServiceProvider().ComputeHash(rawSalted);

                byte[] dbText = new byte[saltedText.Length + saltValue.Length];//保存盐
                saltValue.CopyTo(dbText, 0);
                saltedText.CopyTo(dbText, saltValue.Length);

                return(dbText);
            }
            catch
            {
                throw new Exception("Encrypt Error!");
            }
        }