FormsAuthentication.HashPasswordForStoringInConfigFile 的替代方法
由于项目中要和php对接,要将一段字符串生成md5(16位)验证码,在英文字符时,没有太大问题,但在遇到中文时,两边字条始终不一致。
php是别人的项目,看不到源码,网上一查,估计是这样写的:
<?php
echo substr(md5("admin"),8,16); // 16位MD5加密
echo "<hr>";
echo md5("admin"); // 32位MD5加密
?>
之前的 md5代如下(对md5没有过多研究,这段代码也是网上找的):
public static string Md5_16(string str)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(str)), , );
t2 = t2.Replace("-", "");
t2 = t2.ToLower();
return t2;
}
在苦恼之际,想到以前还有一种md5的做法,得出的值和php生成的一比对,是正确的。但现在4.5环境下警告该方法过期了
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower(); //32位 return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(, ); //16位
本着认真负责的精神,再找找找(刚好也有时间),结果还是在msdn上找到的一段代码,只不过把 HashPasswordForStoringInConfigFile 这个方法重新实现了下
public static string GetMd5Hash(string input)
{
MD5 md5Hash = MD5.Create(); // Convert the input string to a byte array and compute the hash.
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); // Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder(); // Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = ; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
} // Return the hexadecimal string.
return sBuilder.ToString();
}
来源链接:https://social.msdn.microsoft.com/Forums/zh-TW/590bd6a8-57d7-4041-81da-80fe8b832b77/md5
FormsAuthentication.HashPasswordForStoringInConfigFile 的替代方法的更多相关文章
- FormsAuthentication.HashPasswordForStoringInConfigFile方法再.net core中的替代代码
FormsAuthentication.HashPasswordForStoringInConfigFile()这个加密方法再.net core中不存在了,可以用下面的方式达到一样的加密效果 usin ...
- FormsAuthentication.HashPasswordForStoringInConfigFile 方法 之研究
摘自:http://time-is-life.cnblogs.com/articles/322523.html 给定标识哈希类型的密码和字符串,该例程产生一个适合存储在配置文件中的哈希密码. [C#] ...
- System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(string, string)已过时的解决办法
FormsAuthentication.HashPasswordForStoringInConfigFile 方法是一个在.NET 4.5中已经废弃不用的API,参见: https://msdn.mi ...
- iOS中的过期方法和新的替代方法
关于iOS中的过期方法和新的替代方法 1.获取某些类的UINavigationBar的统一外观并设置UINavigationbar的背景 注:方法名改了但是基本使用方法不变 + (instancety ...
- spring替代方法
总结spring替代方法的使用 MyValueCalculator类中的computerValue方法将会被替代 public class MyValueCalculator { public Str ...
- Android中getDrawable和getColor过时的替代方法
版权声明:本文为博主原创文章,未经博主允许不得转载. 前言 Android SDK 升级到 23 之后,getDrawable和getColor方法提示过时. 解决方案 getResources(). ...
- 画删除线的方法,如何找替代方法,Deprecated注释
用@Deprecated注释的程序元素,不鼓励程序员使用这样的元素,通常是因为它很危险或存在更好的选择.在使用不被赞成的程序元素或在不被赞成的代码中执行重写时,编译器会发出警告. 那么相应的替代方法应 ...
- sizeWithFont:的替代方法
sizeWithFont:的替代方法 -(CGFloat)changeStationWidth:(NSString *)string{ UIFont * textFont = [UIFont syst ...
- 新版 Scrapy 中 sys.conf.settings 的替代方法
新版 Scrapy 中 sys.conf.settings 的替代方法 在 scrapy 项目目录下,有个 settings.py 文件,此文件是用来存放爬虫项目的各种配置,比如说 MongoDB 的 ...
随机推荐
- dubbo filter链构建过程
public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException { if (Consta ...
- HDFS High Availability Using the Quorum Journal Manager
http://hadoop.apache.org/docs/r2.9.0/hadoop-project-dist/hadoop-hdfs/HDFSHighAvailabilityWithQJM.htm ...
- 模拟uClinux系统调用
这篇文章原来放在CU上的,现在挪过来了.CU上设置不可见了. 1. 目标 这里主要是实验一下uclinux的系统调用. 2. 环境 OS :vmware + red ...
- COM学习(二)——COM的注册和卸载
COM组件是跨语言的,组件被注册到注册表中,在加载时由加载函数在注册表中查找到对应模块的路径并进行相关加载.它的存储规则如下: 1. 在注册表的HKEY_CLASSES_ROOT中以模块名的方式保存着 ...
- 易卡易APP的出现改变你的消费习惯
科技发展越来越快,移动支付占据市场主导地位,银行业发展受到了重大冲击,致使银行对于信用卡的推广更加重视.人们的消费观念也受到了很大影响从以前的现金消费变成现在的数字消费,人们对于金钱的观念就是一个数字 ...
- 关于centos启动报错:Failed to start Crash recovery kernel arming的解决方案
在VMware中安装了centos,重启时报错:Failed to start Crash recovery kernel arming 本质是kdump服务启动失败 先来说一下,什么是kdump K ...
- VS2015配置内核WDK7600环境,32位下.
VS2015配置内核WDK7600环境,32位下. 学习内核驱动的编写,就要会配置环境.不然总是用记事本编写.比较不方便. 环境配置如下. 1.首先下载WDK7600, 课堂资料代码中已经上传.链接: ...
- ISE14.7兼容性问题集锦
六.WARNING:iMPACT:923 - Can not find cable, check cable setup ! 这个错误是由于驱动没有安装或者驱动安装有问题,一般ISE会在安装的时候把驱 ...
- Mac效率:配置Alfred web search
// 这是一篇导入进来的旧博客,可能有时效性问题. 想用搜索引擎搜东西,或者查字典时,一般的workflow是:打开浏览器-->打开搜索引擎/字典网站-->输入搜索关键字-->回车. ...
- 2017"百度之星"程序设计大赛 - 复赛1005&&HDU 6148 Valley Numer【数位dp】
Valley Numer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...