当前位置: 首页 > news >正文

提升自己建设自己的网站网站优化排名哪家性价比高

提升自己建设自己的网站,网站优化排名哪家性价比高,山东网站建设设计,深圳网站设计工资一般多少C# | 上位机开发新手指南(六)摘要算法 文章目录C# | 上位机开发新手指南(六)摘要算法前言常见摘要算法源码MD5算法SHA-1算法SHA-256算法SHA-512算法BLAKE2算法RIPEMD算法Whirlpool算法前言 你知道摘要算法么?它在保障…

C# | 上位机开发新手指南(六)摘要算法

文章目录

  • C# | 上位机开发新手指南(六)摘要算法
    • 前言
    • 常见摘要算法源码
      • MD5算法
      • SHA-1算法
      • SHA-256算法
      • SHA-512算法
      • BLAKE2算法
      • RIPEMD算法
      • Whirlpool算法

前言

你知道摘要算法么?它在保障数据安全方面非常有用!

它能够将任意长度的数据转换成固定长度的消息摘要,从而确保数据的完整性和可靠性。比如说,我们下载软件的时候,就可以用摘要算法来检验软件是否被篡改,保障我们的电脑安全。

那这个算法的工作原理是怎样的呢?大致就是通过一系列复杂的计算,将原始数据转换为一个固定长度的摘要信息。而且无论输入的数据大小,输出的摘要信息长度都是一样的。

那么摘要算法有什么用处呢?比如数字签名,确保数据的来源和内容没有被篡改。还有密码学等领域的应用,可以说是非常厉害了!

那常见的摘要算法有哪些呢?比较常见的有MD5、SHA-1、SHA-2、SHA-3、BLAKE2、RIPEMD、Whirlpool和Keccak等。它们各有不同的优缺点和适用场景,我们需要根据实际情况来选择使用哦。

常见摘要算法源码

MD5算法

MD5是一种广泛使用的哈希算法,将任意长度的数据计算为128位的哈希值。尽管它被广泛使用,但是因为它已经被证明存在安全漏洞,现在已经不再被推荐使用。

示例代码:

using System;
using System.Security.Cryptography;
using System.Text;class Program
{static void Main(string[] args){string input = "Hello, world!";// 使用 MD5 算法生成摘要string md5Hash = GetMd5Hash(input);Console.WriteLine($"MD5 hash of {input}: {md5Hash}");}// 使用 MD5 算法生成摘要static string GetMd5Hash(string input){using (MD5 md5 = MD5.Create()){// 将输入字符串转换为字节数组byte[] inputBytes = Encoding.UTF8.GetBytes(input);// 计算哈希值byte[] hashBytes = md5.ComputeHash(inputBytes);// 将哈希值转换为字符串StringBuilder builder = new StringBuilder();for (int i = 0; i < hashBytes.Length; i++){builder.Append(hashBytes[i].ToString("x2"));}return builder.ToString();}}
}

代码中使用了 System.Security.Cryptography 命名空间中的 MD5 类。在方法中,先将字符串转换为字节数组,然后调用 MD5 类的 ComputeHash 方法生成哈希值,最后将哈希值转换为字符串返回。

SHA-1算法

SHA-1是一种用于计算数据哈希值的加密算法,将任意长度的数据计算为160位的哈希值。目前,SHA-1算法也已经被证明存在安全漏洞,现在不再被推荐使用。

示例代码:

using System;
using System.Security.Cryptography;
using System.Text;class Program
{static void Main(string[] args){string input = "Hello, world!";// 使用 SHA-1 算法生成摘要string sha1Hash = GetSha1Hash(input);Console.WriteLine($"SHA-1 hash of {input}: {sha1Hash}");}// 使用 SHA-1 算法生成摘要static string GetSha1Hash(string input){using (SHA1 sha1 = SHA1.Create()){// 将输入字符串转换为字节数组byte[] inputBytes = Encoding.UTF8.GetBytes(input);// 计算哈希值byte[] hashBytes = sha1.ComputeHash(inputBytes);// 将哈希值转换为字符串StringBuilder builder = new StringBuilder();for (int i = 0; i < hashBytes.Length; i++){builder.Append(hashBytes[i].ToString("x2"));}return builder.ToString();}}
}

代码中使用了 System.Security.Cryptography 命名空间中的 SHA1 类。在方法中,先将字符串转换为字节数组,然后调用 SHA1 类的 ComputeHash 方法生成哈希值,最后将哈希值转换为字符串返回。

SHA-256算法

SHA-256是一种用于计算数据哈希值的加密算法,将任意长度的数据计算为256位的哈希值。它是SHA-2算法族中的一员,比SHA-1更安全。

示例代码:

using System;
using System.Security.Cryptography;
using System.Text;class Program
{static void Main(string[] args){string input = "Hello, world!";// 使用 SHA-256 算法生成摘要string sha256Hash = GetSha256Hash(input);Console.WriteLine($"SHA-256 hash of {input}: {sha256Hash}");}// 使用 SHA-256 算法生成摘要static string GetSha256Hash(string input){using (SHA256 sha256 = SHA256.Create()){// 将输入字符串转换为字节数组byte[] inputBytes = Encoding.UTF8.GetBytes(input);// 计算哈希值byte[] hashBytes = sha256.ComputeHash(inputBytes);// 将哈希值转换为字符串StringBuilder builder = new StringBuilder();for (int i = 0; i < hashBytes.Length; i++){builder.Append(hashBytes[i].ToString("x2"));}return builder.ToString();}}
}

代码中使用了 System.Security.Cryptography 命名空间中的 SHA256 类。在方法中,先将字符串转换为字节数组,然后调用 SHA256 类的 ComputeHash 方法生成哈希值,最后将哈希值转换为字符串返回。

SHA-512算法

SHA-512是一种用于计算数据哈希值的加密算法,将任意长度的数据计算为512位的哈希值。它是SHA-2算法族中的一员,比SHA-256更安全。

示例代码:

using System;
using System.Security.Cryptography;
using System.Text;class Program
{static void Main(string[] args){string input = "Hello, world!";// 使用 SHA-512 算法生成摘要string sha512Hash = GetSha512Hash(input);Console.WriteLine($"SHA-512 hash of {input}: {sha512Hash}");}// 使用 SHA-512 算法生成摘要static string GetSha512Hash(string input){using (SHA512 sha512 = SHA512.Create()){// 将输入字符串转换为字节数组byte[] inputBytes = Encoding.UTF8.GetBytes(input);// 计算哈希值byte[] hashBytes = sha512.ComputeHash(inputBytes);// 将哈希值转换为字符串StringBuilder builder = new StringBuilder();for (int i = 0; i < hashBytes.Length; i++){builder.Append(hashBytes[i].ToString("x2"));}return builder.ToString();}}
}

代码中使用了 System.Security.Cryptography 命名空间中的 SHA512 类。在方法中,先将字符串转换为字节数组,然后调用 SHA512 类的 ComputeHash 方法生成哈希值,最后将哈希值转换为字符串返回。

BLAKE2算法

BLAKE2是BLAKE算法的改进版,是一种快速、安全的哈希函数,支持多种哈希长度,其中BLAKE2b和BLAKE2s分别支持512位和256位哈希值。它在安全性和性能方面都表现优异,被广泛应用于密码学和安全领域。

示例代码:

using System;
using System.Security.Cryptography;
using System.Text;class Program
{static void Main(string[] args){string input = "Hello, world!";// 使用 BLAKE2 算法生成摘要string blake2bHash = GetBlake2bHash(input);Console.WriteLine($"BLAKE2b hash of {input}: {blake2bHash}");string blake2sHash = GetBlake2sHash(input);Console.WriteLine($"BLAKE2s hash of {input}: {blake2sHash}");}// 使用 BLAKE2b 算法生成摘要static string GetBlake2bHash(string input){using (BLAKE2b blake2b = BLAKE2b.Create()){// 将输入字符串转换为字节数组byte[] inputBytes = Encoding.UTF8.GetBytes(input);// 计算哈希值byte[] hashBytes = blake2b.ComputeHash(inputBytes);// 将哈希值转换为字符串StringBuilder builder = new StringBuilder();for (int i = 0; i < hashBytes.Length; i++){builder.Append(hashBytes[i].ToString("x2"));}return builder.ToString();}}// 使用 BLAKE2s 算法生成摘要static string GetBlake2sHash(string input){using (BLAKE2s blake2s = BLAKE2s.Create()){// 将输入字符串转换为字节数组byte[] inputBytes = Encoding.UTF8.GetBytes(input);// 计算哈希值byte[] hashBytes = blake2s.ComputeHash(inputBytes);// 将哈希值转换为字符串StringBuilder builder = new StringBuilder();for (int i = 0; i < hashBytes.Length; i++){builder.Append(hashBytes[i].ToString("x2"));}return builder.ToString();}}
}

代码中使用了 System.Security.Cryptography 命名空间中的 BLAKE2b 和 BLAKE2s 类。在方法中,先将字符串转换为字节数组,然后调用 BLAKE2 类的 ComputeHash 方法生成哈希值,最后将哈希值转换为字符串返回。

RIPEMD算法

RIPEMD是一种比较老的哈希算法,支持多种哈希长度,其中RIPEMD-160和RIPEMD-256分别支持160位和256位哈希值。它在安全性方面比MD5强,但性能较慢。

示例代码:

using System;
using System.Security.Cryptography;
using System.Text;class Program
{static void Main(string[] args){string input = "Hello, world!";// 使用 RIPEMD-160 算法生成摘要string ripemd160Hash = GetRipemd160Hash(input);Console.WriteLine($"RIPEMD-160 hash of {input}: {ripemd160Hash}");// 使用 RIPEMD-256 算法生成摘要string ripemd256Hash = GetRipemd256Hash(input);Console.WriteLine($"RIPEMD-256 hash of {input}: {ripemd256Hash}");}// 使用 RIPEMD-160 算法生成摘要static string GetRipemd160Hash(string input){using (RIPEMD160 ripemd160 = RIPEMD160.Create()){// 将输入字符串转换为字节数组byte[] inputBytes = Encoding.UTF8.GetBytes(input);// 计算哈希值byte[] hashBytes = ripemd160.ComputeHash(inputBytes);// 将哈希值转换为字符串StringBuilder builder = new StringBuilder();for (int i = 0; i < hashBytes.Length; i++){builder.Append(hashBytes[i].ToString("x2"));}return builder.ToString();}}// 使用 RIPEMD-256 算法生成摘要static string GetRipemd256Hash(string input){using (RIPEMD256 ripemd256 = RIPEMD256.Create()){// 将输入字符串转换为字节数组byte[] inputBytes = Encoding.UTF8.GetBytes(input);// 计算哈希值byte[] hashBytes = ripemd256.ComputeHash(inputBytes);// 将哈希值转换为字符串StringBuilder builder = new StringBuilder();for (int i = 0; i < hashBytes.Length; i++){builder.Append(hashBytes[i].ToString("x2"));}return builder.ToString();}}
}

代码中使用了 System.Security.Cryptography 命名空间中的 RIPEMD160 和 RIPEMD256 类。在方法中,先将字符串转换为字节数组,然后调用 RIPEMD 类的 ComputeHash 方法生成哈希值,最后将哈希值转换为字符串返回。

Whirlpool算法

Whirlpool是一种强度很高的哈希算法,支持512位哈希值。它具有高度的安全性和抗碰撞性,并且被广泛应用于数字签名、身份验证和数据完整性验证等领域。

示例代码:

using System;
using System.Security.Cryptography;
using System.Text;class Program
{static void Main(string[] args){string input = "Hello, world!";// 使用 Whirlpool 算法生成摘要string whirlpoolHash = GetWhirlpoolHash(input);Console.WriteLine($"Whirlpool hash of {input}: {whirlpoolHash}");}// 使用 Whirlpool 算法生成摘要static string GetWhirlpoolHash(string input){using (Whirlpool whirlpool = Whirlpool.Create()){// 将输入字符串转换为字节数组byte[] inputBytes = Encoding.UTF8.GetBytes(input);// 计算哈希值byte[] hashBytes = whirlpool.ComputeHash(inputBytes);// 将哈希值转换为字符串StringBuilder builder = new StringBuilder();for (int i = 0; i < hashBytes.Length; i++){builder.Append(hashBytes[i].ToString("x2"));}return builder.ToString();}}
}

代码中使用了 System.Security.Cryptography 命名空间中的 Whirlpool 类。在方法中,先将字符串转换为字节数组,然后调用 Whirlpool 类的 ComputeHash 方法生成哈希值,最后将哈希值转换为字符串返回。

http://www.mmbaike.com/news/85813.html

相关文章:

  • wordpress wordseo快速排名软件推荐
  • 酒店网站如何做北京百度推广客服电话多少
  • 《30天网站建设实录》seo综合查询工具下载
  • dreamweaver网站模板百度推广开户需要多少钱
  • 嵌入式应用软件开发流程seo专员是什么意思
  • 上海动易 网站电商线上推广渠道
  • 开发一个直播平台需要多少钱湖南靠谱seo优化公司
  • 做电影网站 广告收入推广公众号
  • 国外做游戏的视频网站松松软文平台
  • 网站asp木马删除网上企业推广
  • 电商网站前端设计方案百度首页快速排名系统
  • 苏州建设培训中心网站看颜色应该搜索哪些词汇
  • 怎样优化排名自己网站seo关键词排名优化系统
  • 网投网站建设百度竞价排名又叫什么
  • 娄底网站建设方案百度网站电话是多少
  • 做品牌网站怎么样百度关键词优化平台
  • 网站建设美工招聘百度竞价关键词价格查询
  • 怎么筛选一家做网站做的好的公司网络营销案例成功案例
  • 沈阳个人做网站广东东莞疫情最新消息
  • 网站建设论文的中期报告营销方法有哪几种
  • 哪里有网站建设培训班如何开发一个软件平台
  • 网站服务器有哪些类型有哪些类型有哪些类型有哪些排名第一的助勃药
  • 沈阳高端网站开发建设百度合作平台
  • 做外贸用什么网站比较好营销策划方案公司
  • 做网站发违规内容 网警抓不抓热搜在哪里可以看
  • 网站建设基础策划书企业网站seo推广方案
  • 长沙手机网站建设公司哪家好白帽优化关键词排名seo
  • 花钱推广的网络平台百度seo推广是什么
  • 个人主页界面网站网站建设流程图
  • 廊坊关键词优化平台seo的内容有哪些