请懂Php和C#的朋友看看这两段代码 <?phpecho md5("111111");?>这个结果就是96e79218965eb72c92a549dd5a330112 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的意思是,你就别用phpbb的代码了呗。就用php自带的md5这个函数就行了。 这个php函数可以处理两种格式, md5 + ???根据传入的$hash判断使用那种你确定你php是在使用md5吗? Php 自带了md5这个加密函数,不必那么麻烦. php的只修改md5就好了。要修改.NET的,修改如下// 整个代码可能有大小写问题,protected string Md5(string source) { string result = ""; System.Security.Cryptography.MD5 md5 = MD5 md5 = new MD5CryptoServiceProvider(); byte[] temp = md5.ComputeHash(Encoding.utf8.GetBytes(source)); result = BitConverter.tostring( temp ).replace("-", "").tolower(); return result; } 由于匆忙,上面写错了,呵呵,应该是这样System.Security.Cryptography.MD5 md5 = new MD5CryptoServiceProvider(); md5PHP计算字符串的 MD5 哈稀。语法: string md5(string str);返回值: 字符串函数种类: 编码处理C#网上找到的一个,备查 ------------------------------------------------------------------------------------------------------------------- public string md5(string str, int code) { if (code == 16) //16位MD5加密(取32位加密的9~25字符) { return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16); } if (code == 32) //32位加密 { return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower(); } return "00000000000000000000000000000000"; } protected void Button1_Click(object sender, EventArgs e) { if (ListBox_16.Text.ToString().Trim().Length != 0) { string LockString16; LockString16 = md5(ListBox_16.Text, 16); ListItem li = new ListItem(ListBox_16.Text.ToString() + "==>" + LockString16); this.ListBox_16.Items.Add(li); Response.Write(LockString16); } } 给你个C#的:public static string md5String(string str) { //作为密码方式加密 并返回加密后的值 return FormsAuthentication.HashPasswordForStoringInConfigFile(str.ToString().ToLower(), "MD5").ToLower();//默认生成的是大写 } 再给个PHP的:<?php$str = "Hello";echo md5($str);?>结果为:8b1a9953c4611296a827abf8c47804d7详细资料:http://www.fzs8.net/php/php_tutorial/2007-03-18/1286.html 补充一下:c#要使用这个功能, 需要引用:using System.Web.Security;public static string md5String(string str) { //作为密码方式加密 并返回加密后的值 return FormsAuthentication.HashPasswordForStoringInConfigFile(str.ToString().ToLower(), "MD5").ToLower();//默认生成的是大写 } php 不是有 md5() 函数吗 string MD5(string str) { string md5code = ""; System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();//实例化一个md5对像 // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 byte[] s = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(str)); // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得 for (int i = 0; i < s.Length; i++) { // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符 string temp = s[i].ToString("X2"); md5code = md5code + temp; } return md5code; } public string md5String(string str) { //默认生成的是大写 return FormsAuthentication.HashPasswordForStoringInConfigFile(str.ToString().ToLower(), "MD5").ToLower();//默认生成的是大写 } 以字符串"123"的MD5加密来说:PHP代码: $s= md5("123");C#代码: String s= System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("123","MD5").ToLower();以上两个函数的返回值即:$s和s的值一样,都是:202cb962ac59075b964b07152d234b70 csdn的缓存时间设定是多少呢? php小偷程序的类,都要有什么功能呢? php 替换 开发php,到底用什么工具呢? PHP 生成XML session文件产生太多,怎么办? php是不是有点矛盾? 如何判断标题字数的奇、偶? php 端为什么接受不到andriod 发送(post)过来的json数据 请问那个phpmyadmin是怎么用的..我已经解压了.. php网站显示空白的问题! 求一条格式化时间的SQL语句~~~~~~~~~~~~~~~~~~~~~~~~~~ 请问如何处理这项显示,有关javascript和php,使用于discuz论坛。
根据传入的$hash判断使用那种
你确定你php是在使用md5吗?
Php 自带了md5这个加密函数,不必那么麻烦.
protected string Md5(string source)
{
string result = "";
System.Security.Cryptography.MD5 md5 = MD5 md5 = new MD5CryptoServiceProvider();
byte[] temp = md5.ComputeHash(Encoding.utf8.GetBytes(source));
result = BitConverter.tostring( temp ).replace("-", "").tolower();
return result;
}
System.Security.Cryptography.MD5 md5 = new MD5CryptoServiceProvider();
PHP
计算字符串的 MD5 哈稀。语法: string md5(string str);返回值: 字符串函数种类: 编码处理
C#
网上找到的一个,备查 ------------------------------------------------------------------------------------------------------------------- public string md5(string str, int code)
{
if (code == 16) //16位MD5加密(取32位加密的9~25字符)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
} if (code == 32) //32位加密
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
} return "00000000000000000000000000000000";
}
protected void Button1_Click(object sender, EventArgs e)
{
if (ListBox_16.Text.ToString().Trim().Length != 0)
{
string LockString16;
LockString16 = md5(ListBox_16.Text, 16);
ListItem li = new ListItem(ListBox_16.Text.ToString() + "==>" + LockString16);
this.ListBox_16.Items.Add(li);
Response.Write(LockString16);
} }
{
//作为密码方式加密 并返回加密后的值
return FormsAuthentication.HashPasswordForStoringInConfigFile(str.ToString().ToLower(), "MD5").ToLower();//默认生成的是大写
}
<?php
$str = "Hello";
echo md5($str);
?>结果为:8b1a9953c4611296a827abf8c47804d7详细资料:http://www.fzs8.net/php/php_tutorial/2007-03-18/1286.html
{
//作为密码方式加密 并返回加密后的值
return FormsAuthentication.HashPasswordForStoringInConfigFile(str.ToString().ToLower(), "MD5").ToLower();//默认生成的是大写
}
string MD5(string str) { string md5code = ""; System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();//实例化一个md5对像 // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 byte[] s = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(str)); // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得 for (int i = 0; i < s.Length; i++) { // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符 string temp = s[i].ToString("X2"); md5code = md5code + temp; } return md5code; }
{
//默认生成的是大写
return FormsAuthentication.HashPasswordForStoringInConfigFile(str.ToString().ToLower(), "MD5").ToLower();//默认生成的是大写
}
以字符串"123"的MD5加密来说:PHP代码:
$s= md5("123");C#代码:
String s= System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("123","MD5").ToLower();以上两个函数的返回值即:$s和s的值一样,都是:202cb962ac59075b964b07152d234b70