首次推送
This commit is contained in:
71
Mtxfw.Utility/MD5.cs
Normal file
71
Mtxfw.Utility/MD5.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mtxfw.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// 类名:MD5
|
||||
/// 功能:MD5加密
|
||||
/// 版本:3.3
|
||||
/// 修改日期:2012-07-05
|
||||
/// 说明:
|
||||
/// 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
/// 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
|
||||
/// </summary>
|
||||
public sealed class AlipayMD5
|
||||
{
|
||||
public AlipayMD5()
|
||||
{
|
||||
//
|
||||
// TODO: 在此处添加构造函数逻辑
|
||||
//
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 签名字符串
|
||||
/// </summary>
|
||||
/// <param name="prestr">需要签名的字符串</param>
|
||||
/// <param name="key">密钥</param>
|
||||
/// <param name="_input_charset">编码格式</param>
|
||||
/// <returns>签名结果</returns>
|
||||
public static string Sign(string prestr, string key, string _input_charset)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(32);
|
||||
|
||||
prestr = prestr + key;
|
||||
|
||||
MD5 md5 = new MD5CryptoServiceProvider();
|
||||
byte[] t = md5.ComputeHash(Encoding.GetEncoding(_input_charset).GetBytes(prestr));
|
||||
for (int i = 0; i < t.Length; i++)
|
||||
{
|
||||
sb.Append(t[i].ToString("x").PadLeft(2, '0'));
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证签名
|
||||
/// </summary>
|
||||
/// <param name="prestr">需要签名的字符串</param>
|
||||
/// <param name="sign">签名结果</param>
|
||||
/// <param name="key">密钥</param>
|
||||
/// <param name="_input_charset">编码格式</param>
|
||||
/// <returns>验证结果</returns>
|
||||
public static bool Verify(string prestr, string sign, string key, string _input_charset)
|
||||
{
|
||||
string mysign = Sign(prestr, key, _input_charset);
|
||||
if (mysign == sign)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user