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
"
);
}
}
——宽田 著——
查看全文
相关阅读:
Silverlight入门:第四部分 数据绑定
[Silverlight入门系列]使用MVVM模式(6):使用Behavior
Silverlight入门:第二部分 定义界面布局和导航
[Silverlight入门系列]使用MVVM模式(2):集合Model /ObservableCollection/ICollectionView
建立可扩展的silverlight应用框架 step5:整理Module
Silverlight入门:第六部分 美化用户界面的样式与模板
[Silverlight入门系列]使用MVVM模式(7):ViewModel的INotifyPropertyChanged接口实现
Silverlight WCF RIA服务(五)使用SL商业应用模板
Silverlight WCF RIA服务(四)如何添加和移除RIA Services Link
Asymptote 学习记录(3) 画赵爽弦图练习
原文地址:https://www.cnblogs.com/scottckt/p/1029553.html
最新文章
5 Minute Overview of MVVM in Silverlight
Silverlight WCF RIA服务(一)简介
[Silverlight入门系列]使用MVVM模式(9): 想在ViewModel中控制Storyboard动画?
建立可扩展的silverlight应用框架 step2
Silverlight WCF RIA服务(八)Domain Services 1
[Silverlight入门系列]使用MVVM模式(1):MVVM核心概念
Silverlight WCF RIA服务(九)Domain Service 2
Siverlight5新功能/改进总结
Silverlight WCF RIA服务(六)创建RIA Services 类库
建立可扩展的silverlight应用框架
热门文章
建立可扩展的silverlight应用框架 step4
Silverlight WCF RIA服务 (二)解决方案结构
Model–View–ViewModel in Silverlight
Silverlight WCF RIA服务(七)中间层简介
Silverlight入门系列]使用MVVM模式
Silverlight WCF RIA服务(十二) 数据 2
Silverlight WCF RIA服务(十)Domain Services 3
[Silverlight入门系列]使用MVVM模式(3):Model的INotifyPropertyChanged接口实现
[Silverlight入门系列]使用MVVM模式(4):Prism的NotificationObject自动实现INotifyPropertyChanged接口
[Silverlight入门系列]使用MVVM模式(5):异步Validation数据验证和INotifyDataErrorInfo接口
Copyright © 2011-2022 走看看