zoukankan
html css js c++ java
c# 中對輸入的值用md5或Hash加密
using
System.Security.Cryptography;
/**/
///
<summary>
///
MD5加密方法
///
</summary>
///
<param name="asSource">
源Md5值
</param>
///
<param name="asDestination">
需對比的字符
</param>
///
<returns>
是否正確
</returns>
private
bool
Md5EncryptJudge(
string
asSource,
string
asDestination)
{
bool
bResult
=
false
;
string
sDestination
=
""
;
//
定義Md5密碼服務類
MD5CryptoServiceProvider mdcpValu
=
new
MD5CryptoServiceProvider();
//
將傳入的值轉換成UTF8格式。便於加密時的格式統一
byte
[] bDestination
=
System.Text.Encoding.UTF8.GetBytes(asDestination);
//
加密
byte
[] bDestinationMd5
=
mdcpValu.ComputeHash(bDestination);
//
將加密后的值賦給字符串
foreach
(
byte
bVal
in
bDestinationMd5)
{
sDestination
+=
bVal.ToString();
}
//
判斷需對比的值加密成md5后與傳入的MD5值是否與傳入的相等
if
(asSource
==
sDestination)
{
bResult
=
true
;
}
else
{
bResult
=
false
;
}
return
bResult;
}
/**/
///
<summary>
///
Hash加密
///
</summary>
///
<param name="asSource">
源加密后的值
</param>
///
<param name="asDestination">
目標字符串
</param>
private
void
HashEncrypt(
string
sScouce,
string
asDestination)
{
byte
[] bDestinationValue
=
System.Text.Encoding.UTF8.GetBytes(asDestination);
HMACSHA1 hsVal
=
new
HMACSHA1();
//
加密
byte
[] bHmacshaValue
=
hsVal.ComputeHash(bDestinationValue);
//
將加密后的值轉換為字符
string
sDesHmaVal
=
Convert.ToBase64String(bHmacshaValue);
if
(sScouce
==
sDesHmaVal)
{
MessageBox.Show(
"
Ok
"
);
}
else
{
MessageBox.Show(
"
False
"
);
}
}
——宽田 著——
查看全文
相关阅读:
闭包的应用(转载)
智能社讲解js基础
HTML5 Geolocation
Redis主从配置
Redis序列化配置
Ribbon负载均衡原理学习记录
2059 mysql
Cache缓存
rabbitmq(三)-Direct交换器
rabbitmq(二)原理
原文地址:https://www.cnblogs.com/scottckt/p/1029553.html
最新文章
面向对象总结
集合框架
网络编程(一)
XML文件
多线程二
COUNT distinct多个字段,结果不等于COUNT (distinct结果表)的某一字段
mysql 修改某列数据类型一直运行中
SQL聚合函数中包含计算,列数据属性非数据格式则计算结果出错
python BeautifulSoup4 获取 script 节点问题
批量注释 control+/
热门文章
TypeError: 'list' object cannot be interpreted as an integer
表达式语句
(h,v) represent (horizontal,vertical)
history-back
正则整理(转载)
DNS域名解析10步
转载-cookie和session的窃取
一些简单的SQL语句
一些总结
ajax全局
Copyright © 2011-2022 走看看