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
"
);
}
}
——宽田 著——
查看全文
相关阅读:
第21周六
第21周五
第21周四
第21周三
C/C++中各种类型int、long、double、char表示范围(最大最小值)
插入排序
面向对象的5个基本设计原则
红黑树
Cocos2d-x学习笔记(六) 定时器Schedule的简单应用
SNMP协议具体解释
原文地址:https://www.cnblogs.com/scottckt/p/1029553.html
最新文章
[转] “error LNK2019: 无法解析的外部符号”之分析
[转] GIS二次开发(C#+AE)
实现高程点到等高线的转换
Arc Engine 中添加气泡提示框
[Elasticsearch] 部分匹配 (一)
mysql压力测试
如何出色的研究 RGSS3 (三) 形式的调整的细节
有些创业经验分享(1)——创业杂谈
有趣 IOS 开展
HDU 1505 City Game(01矩阵 dp)
热门文章
多于ListView同步滚动
linux网络编程投票
简单的无锁队列环形实现
【C语言】reverse_string(char * string)(递归)
第22周五
第22周四
第22周三
第22周二
第22周一
2014第21周日
Copyright © 2011-2022 走看看