Exemple #1
0
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="plainText">明文</param>
        /// <param name="encryptKey">加密密钥(加密密钥为null)</param>
        /// <returns></returns>
        public string Encrypt(string plainText, string encryptKey)
        {
            //将明文转为字节数组
            byte[] arrPlainText = Encoding.UTF8.GetBytes(plainText);
            //计算字节数组的哈希值
            byte[] arrHash = mCrypto.ComputeHash(arrPlainText);
            mCrypto.Clear();

            StringBuilder result = new StringBuilder();

            for (int i = 0; i < arrHash.Length; i++)
            {
                result.Append(arrHash[i].ToString("x2"));
            }
            return(result.ToString());
        }