All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Visual C++ 6.0教程:C++主要特点
怎样在vb.net中将图片存入SQL,Server,2000并能读出来使用
asp.net连接Access数据库_[Asp.Net教程]
iframe的高度随内容的变化而变化_[Html教程]
浅谈.NET中的数据绑定表达式(二)_[Asp.Net教程]
使用ASP.NET,2.0中的ReportViewer控件_.net资料_编程技术
SQL,Server,2005—有关开发的10个最重要的特点_[SQL,Server教程]
delphi类的多态性
ASP.NET,2.0高级数据处理之冲突检测_.net资料_编程技术
ASP.NET从零起步设计网站全过程(10)_[Asp.Net教程]
Reading number is top 10 pictures
The money of more than 100 countries and regions17
Born After 90 Beijing sports university campus flower photos1
Wear bikinis cock
含苞欲放的素颜美少女3
战场废物2
鸡蛋的新玩法
看看什么叫美景
明星与豪宅
9.3阅兵全景图5-地空反舰导弹梯队
The woman fight much more than men
Download software ranking
仙剑奇侠传98版歌曲
Eclipse 4.2.1 For Win32
Tram sex maniac 2 (H) rar bag11
超级战舰
Unix video tutorial20
金山office2007
软件工程思想
Tram sex maniac 2 (H) rar bag2
艳兽都市
XML+Web+Service开发教程
delv published in(发表于) 2014/1/27 6:47:19 Edit(编辑)
Asp.Net,加密示例_[Asp.Net教程]

Asp.Net,加密示例_[Asp.Net教程]

Asp.Net 加密示例_[Asp.Net教程]

SHA1算法的散列值大小为160位。一般的加密方式为
byte[] data=System.Text.Encoding.Unicode.GetBytes(source.ToCharArray());
System.Security.Cryptography.SHA1 sha=new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] result=sha.ComputeHash(data);
使用SHA1对密码实现加密,需要使用以下的方法:
string EnPswdStr=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(source, "MD5");
或许有的人会问,既然都是采用SHA1方法加密,为什么对密码的加密就不能使用原方法呢?因为一般情况下SHA1方法加密出来的密码并不是常规字符,有些字符甚至无法显示出来,如果使用这样的字符作为密码,在存入数据库时有些字符会被处理掉,这样加密结果就会失真,在进行密码验证时就会出现无法预料的差错。而采用密码加密函数的话就避免了这一个问题,它加密出来的结果都是常规字符,在数据库进行存储和程序处理时不会失真。

下面是例子程序:
Default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>





无标题页

























Default.aspx.cs


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
//获取要加密的字段,并转化为byte[]数组
byte[] data = System.Text.Encoding.Unicode.GetBytes(TextBox1.Text.ToCharArray());
//建立加密服务
System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
//加密byte[]数组
byte[] result = sha.ComputeHash(data);
//将加密后的数组转化为字符串
string sResult = System.Text.Encoding.Unicode.GetString(result);
//显示出来
Label1.Text = "SHA1普通加密:" + sResult.ToString() + "
";
//作为密码方式加密
string EnPswdStr = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text.ToString(), "MD5");
//显示出来
Label2.Text = "SHA1密码加密:" + EnPswdStr + "
";
}


}
}

运行效果图:


输入22然后点加密:



来源:xingyao的blog







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.