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);
}
}
}
解决方案 »
- serialPort,使用USB转串口发送接收,当拔下设备再插上,串口在使用的途中会抛出错误,用Try..Catch都无法捕获.怎么办?
- 改了MySQL连接字符串设置,MySQLDataAdapter对象的fill方法就抛出异常了。怎么回事?
- 关于C# ORACLE 问题
- 关于c#很基本的问题?
- 索引功能如何实现?
- SOS!!!怎样判断登录的用户名和GridView中的一列显示用户名是否相等。
- 请教,DataSet怎样保存到.txt文本文档?在线等候。。。。
- 非常紧急,存储过程在C#中调用会出错,如果在SQL SERVER的查询分析器中执行会成功,这是什么问题?
- 如何实现在windows service启动的时候同时启动一个winform?
- 初学者问:给一大段代码打注释有什么快捷键?
- 请教三个简单的问题!
- 请问知道一些接口,比如发短信,支付宝之类是不是就能实现功能?
根据程序里面的输入:10.128.174.30
输出是:bpTuefqAmNNc3wmkZJstPoB1lH8=而且貌似每次最后都具有一个“=”
不知道为什么,请大家指点一下
因为我最终想要的是16进制的,可比较的形式
{
byte[] bytIn = UTF8Encoding.UTF8.GetBytes(Source);
byte[] bytOut = HashCryptoService.ComputeHash(bytIn);
return BitConverter.ToString(bytOut);
}