您可以在这里快速查找:


 
您的位置: 编程学习 > asp.net教程 > 200508
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

用C#实现的数据加密(二) —— 哈希算法

chrch

用C#实现的数据加密(二) —— 哈希算法

     以下是用C#实现的哈希加密,大家可以根据自己的需要更改所需的算法,文中以SHA1为例:

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace DataCrypto
{
 /// <summary>
 /// 哈希加密类
 /// </summary>
 public class HashMethod
 {
  
  private HashAlgorithm HashCryptoService;
  /// <summary>
  /// 哈希加密类的构造函数
  /// </summary>
  public HashMethod()
  {
   HashCryptoService = new SHA1Managed();
  }
  /// <summary>
  /// 加密方法
  /// </summary>
  /// <param name="Source">待加密的串</param>
  /// <returns>经过加密的串</returns>
  public string Encrypto(string Source)
  {
   byte[] bytIn = UTF8Encoding.UTF8.GetBytes(Source);
   byte[] bytOut = HashCryptoService.ComputeHash(bytIn);
   return Convert.ToBase64String(bytOut);
  }
 }
}