Beispiel #1
0
        /// <summary>
        /// Sha256加密
        /// </summary>
        /// <param name="str">要加密的字符串</param>
        /// <returns></returns>
        static public string sha256(string str)
        {
            byte[] bytes = CryptoString.stringToBytes(str);
            System.Security.Cryptography.SHA256 sha256 = new SHA256CryptoServiceProvider();
            byte[]        retval = sha256.ComputeHash(bytes);
            StringBuilder sb     = new StringBuilder();

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