求支付宝md5加密方法

greatbag 2005-10-26 05:21:27
请不要给我
static public string ByteArrayToHexString(byte[] buff)
{
StringBuilder sb = new StringBuilder(buff.Length);
for (int i = 0; i < buff.Length; i++)
{
sb.AppendFormat("{0:x2}", buff);
}

return sb.ToString();
}

public static string GetMD5(string key)
{
MD5 md5 = MD5.Create();
byte[] buffer= md5.ComputeHash(System.Text.Encoding.GetEncoding("GB2312").GetBytes(key));
return ByteArrayToHexString(buffer);
}
public static bool VerifyMD5(string key, string md5)
{
return GetMD5(key) == md5;
}
这个是错误的
...全文
523 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
pmmx 2005-10-26
  • 打赏
  • 举报
回复
this.lbl16.Text=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.tbinput.Text.ToString(),"MD5").ToLower().Substring(8,16);

这是十六位的MD5,楼主拿过去试试,asp成生的差不多都是这样的md5
pontus 2005-10-26
  • 打赏
  • 举报
回复
public static string GetMD5(string s)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] t = md5.ComputeHash( Encoding.GetEncoding("gb2312").GetBytes(s) );
StringBuilder sb = new StringBuilder(32);
for(int i=0; i<t.Length; i++)
{
sb.Append( t[i].ToString("x").PadLeft(2, '0'));
}
return sb.ToString();
}
cthiro123 2005-10-26
  • 打赏
  • 举报
回复
ding
greatbag 2005-10-26
  • 打赏
  • 举报
回复
请注意:FormsAuthentication.HashPasswordForStoringInConfigFile()生成的是编码为GBK的吗?

我需要的是用于支付宝的md5加密方法,哪位有做过支付宝集成的请帮帮忙,谢谢
ChengKing 2005-10-26
  • 打赏
  • 举报
回复
(一).功能
用哈希算法: SHA1或MD5 实现用户账号和密码验证.
数据库存储实现原理是: 用户账号直接存储在数据库中,密码经过加密后再存储到数据库中.
当用户登录时,密码要经过加密后再与数据库中的实际存储密码比较,确定是否合法用户.
(二).代码及实现

1.打开命名空间:
using System.Web.Security;


2.在用户注册界面,简要代码:
Regist(UserID.Text,FormsAuthentication.HashPasswordForStoringInConfigFile(Password.Text,"MD5"));

其中: UserID.Text表示用户ID,即注册登录帐号; Password.Text表示注册密码
Regist实现将账号和加密后的密码字符串存储到数据库中.

3.在登录界面,简要代码:

Check(UserID.Text,FormsAuthentication.HashPasswordForStoringInConfigFile(Password.Text,"MD5"));
其中: UserID.Text表示注册成功用户ID,即已经存在的登录帐号; Password.Text表示登录用户的密码
Regist实现用户输入的账号和加密后的密码 与数据库中的帐号密码是否匹配.

数据库其实只是存储了加密后的字符串而已。 除了密码加密,还可以对“提示问题”“提示问题答案”等其它存储,
实现原理是一样的.
greatbag 2005-10-26
  • 打赏
  • 举报
回复
MD5时请确保字符串编码为GBK的
adandelion 2005-10-26
  • 打赏
  • 举报
回复
写个简单的方法.
using System.Web.Security;
using System.Security;

public string MakeMd5(string str)
{
string strReturn = FormsAuthentication.HashPasswordForStoringInConfigFile(str,"md5");
return strReturn;
}

string strPassword ="123456";
string strMd5=MakeMd5(strPassword);
Response.Write(strMd5);
menuvb 2005-10-26
  • 打赏
  • 举报
回复
还有一种方法可以生成MD5,就是使用MD5类.不过好像跟直接FormsAuthentication.HashPasswordForStoringInConfigFile(strPassword,"md5");生成的密码是不一样的.

我忘记怎么写的.
v192 2005-10-26
  • 打赏
  • 举报
回复
上述正解
adandelion 2005-10-26
  • 打赏
  • 举报
回复
using System.Web.Security;
using System.Security;

string strPassword ="123456";
string strMd5=FormsAuthentication.HashPasswordForStoringInConfigFile(strPassword,"md5");
Response.Write(strMd5);

OK了,不用自己写的系统已经有了.

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧