当前位置: 首页>>代码示例>>C#>>正文


C# SHA256Managed.Aggregate方法代码示例

本文整理汇总了C#中System.Security.Cryptography.SHA256Managed.Aggregate方法的典型用法代码示例。如果您正苦于以下问题:C# SHA256Managed.Aggregate方法的具体用法?C# SHA256Managed.Aggregate怎么用?C# SHA256Managed.Aggregate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.SHA256Managed的用法示例。


在下文中一共展示了SHA256Managed.Aggregate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HexSha256

        public static string HexSha256(string text)
        {
            const string salt = "jk#=¤)\"gld\"2347X#Z472\\!";
            var hash = new SHA256Managed().ComputeHash(Encoding.ASCII.GetBytes(text + salt));

            return hash.Aggregate("", (current, x) => current + string.Format("{0:x2}", x));
        }
开发者ID:creodeus,项目名称:SystemOverWatch,代码行数:7,代码来源:Hash.cs

示例2: ToSha256

        /// <summary>
        /// Convert string to sha256 hash
        /// </summary>
        /// <param name="data">string to convert</param>
        /// <returns>sha256 hash or null</returns>
        public static string ToSha256(this string data)
        {
            try
            {
                if (String.IsNullOrEmpty(data))
                    return null;

                var hashValue = new SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(data));
                var hex = hashValue.Aggregate("", (current, x) => current + String.Format("{0:x2}", x));

                if (String.IsNullOrEmpty(hex))
                    throw new Exception("Erro creating SHA256 hash");

                return hex;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return null;
            }
        }
开发者ID:jornfilho,项目名称:.net-Dev-Utils,代码行数:26,代码来源:Sha256.cs


注:本文中的System.Security.Cryptography.SHA256Managed.Aggregate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。