您的位置: 旅游网 > 女人

ASPNET中使用MD5和SHA1算法加

发布时间:2019-06-20 01:14:59

  你的主页或者你管理的站有各种密码需要保护,把密码直接放在数据库或者文件中存在不少安全隐患,所以密码加密后存储是最常见的做法。在中实现加密非常容易。.NET SDK中提供了CookieAuthentication类,其中的HashPasswordForStoringInConfigFile方法可直接使用MD5和SHA1算法。例子如下:

  file: px

  <%@ Page language="c#" Codebehind="" AutoEventWireup="false" Inherits="crypting" %>

  <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:

  namespace encrypting

  {

  using System;

  using llections;

  using ponentModel;

  using ta;

  using awing;

  using b;

  using ssionState;

  using ;

  using bControls;

  using mlControls;

  using curity;

  /// <summary>

  /// Summary description for encrypting.

  /// </summary>

  public class encrypting : ge

  {

  protected bel MD5;

  protected tton Button1;

  protected xtBox TextBox1;

  public encrypting()

  {

  it += new entHandler(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()

  {

  ick += new entHandler (tton1_Click);

  ad += new entHandler (ge_Load);

  }

  public void Button1_Click (object sender, entArgs e)

  {

  xt = shPasswordForStoringInConfigFile(xt,"MD5");

  //SHA1 use shPasswordForStoringInConfigFile(xt,"SHA1");

  }

  }

  }

  注意:类CookieAuthentication的namespace是curity。 查看本文来源

小孩便秘怎么马上通便
小孩经常便秘怎么办
小孩子便秘怎么调理
猜你会喜欢的
猜你会喜欢的