ASP.NET中使用MD5和SHA1算法加密
注意:类CookieAuthentication的namespace是System.Web.Security。
发布日期:2021-06-30 19:07:09
浏览次数:2
分类:技术文章
本文共 2298 字,大约阅读时间需要 7 分钟。
你的主页或者你管理的网站有各种密码需要保护,把密码直接放在数据库或者文件中存在不少安全隐患,所以密码加密后存储是最常见的做法。在ASP.NET中实现加密非常容易。.NET SDK中提供了CookieAuthentication类,其中的HashPasswordForStoringInConfigFile方法可直接使用MD5和SHA1算法。例子如下: file: encrypting.aspx<%@ Page language="c#" Codebehind="encrypting.cs" AutoEventWireup="false" Inherits="encrypting.encrypting" %><html><head><meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"><meta name="CODE_LANGUAGE" Content="C#"></head><body><form method="post" runat="server"><asp:TextBox id=TextBox1 runat="server"></asp:TextBox><asp:Button id=Button1 runat="server" Text="encrypting"></asp:Button>Encrypting Password(MD5):<asp:Label id=MD5 runat="server"></asp:Label></form></body></html>file:encrypting.csnamespace encrypting{ using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Web.Security;/// <summary>/// Summary description for encrypting./// </summary>public class encrypting : System.Web.UI.Page{ protected System.Web.UI.WebControls.Label MD5; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.TextBox TextBox1; public encrypting() { Page.Init += new System.EventHandler(Page_Init); } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // // Evals true first time browser hits the page // } } protected void Page_Init(object sender, EventArgs e) { // // CODEGEN: This call is required by the ASP+ Windows Form Designer. // InitializeComponent(); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { Button1.Click += new System.EventHandler (this.Button1_Click); this.Load += new System.EventHandler (this.Page_Load); } public void Button1_Click (object sender, System.EventArgs e) { MD5.Text = CookieAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text,"MD5"); //SHA1 use CookieAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text,"SHA1"); }}} |
转载地址:https://linuxstyle.blog.csdn.net/article/details/1536733 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
感谢大佬
[***.8.128.20]2024年04月25日 13时16分40秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Mysql 之主从复制
2019-04-30
LVS负载均衡------NAT模式
2019-04-30
squid代理-----透明代理模式
2019-04-30
squid代理介绍----ACL控制应用+sarg日志分析+反向代理
2019-04-30
redis集群之主从模式+哨兵模式
2019-04-30
JavaScript原生开关灯效果
2019-04-30
企业邮箱如何申请注册,邮箱申请如何免费注册?
2019-04-30
微信企业邮箱,手机邮箱格式地址怎么写?
2019-04-30
公司如何申请企业邮箱,公司邮箱怎么申请,公司企业邮箱哪个好?
2019-04-30
电子邮箱账号怎么申请,怎样申请邮箱账号呢
2019-04-30
邮箱怎么发邮件,邮件发信量多少,职场新人怎么发汇报邮件呢?
2019-04-30
maven 多层次pom 新引入包,编译成功,还是没有将包引入到本地
2019-04-30
leetCode2 两数相加
2019-04-30
【工具使用】使用pip与conda安装、更新与卸载Pytorch和torchvision
2019-04-30
【工具使用】Google免费云环境Colaboratory使用
2019-04-30
【深度学习笔记】卷积层,全连接层,池化层的相关输出参数计算
2019-04-30