using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;namespace Cryptography
{
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);
}
static void Main(string[] args)
{
HashMethod hashMethod = new HashMethod();
String str = hashMethod.Encrypto("10.128.174.30");
Console.WriteLine(str);
}
}
}
根据程序里面的输入:10.128.174.30
输出是:bpTuefqAmNNc3wmkZJstPoB1lH8=而且貌似每次最后都具有一个“=”
不知道为什么,请大家指点一下
因为我最终想要的是16进制的,可比较的形式
{
byte[] bytIn = UTF8Encoding.UTF8.GetBytes(Source);
byte[] bytOut = HashCryptoService.ComputeHash(bytIn);
return BitConverter.ToString(bytOut);
}