哈希算法实现ASP.NET数据加密的过程是什么呢?来开始我们的讲述:
以下是用C#实现的哈希加密,大家可以根据自己的需要更改所需的算法,文中以SHA1为例:
- using System;
- using System.IO;
- using System.Security.Cryptography;
- using System.Text;
-
- namespace DataCrypto
- {
-
-
-
- public class HashMethod
- {
-
- private HashAlgorithm HashCryptoService;
-
-
-
- public HashMethod()
- {
- HashCryptoService = new SHA1Managed();
- }
-
-
-
-
-
- public string Encrypto(string Source)
- {
- byte[] bytIn = UTF8Encoding.UTF8.GetBytes(Source);
- byte[] bytOut = HashCryptoService.ComputeHash(bytIn);
- return Convert.ToBase64String(bytOut);
- }
- }
- }
实现ASP.NET数据加密的哈希算法就向你介绍到这里,希望对你有所帮助 。