C# 加密-MD5 和 SHA1
在 ASP.NET 中可以非常方便地执行 MD5
或 SHA1 加密。
<%@ Import Namespace="System.Web.Security" %>
FormsAuthentication.HashPasswordForStoringInConfigFile
只需要两步,第一步引入名称空间
(该名称空间也可以省略引用),第二步执行加密函数。
FormsAuthentication.HashPasswordForStoringInConfigFile 有两个参数:第一个参数是要加密的字符串;第二个参数可选值有 MD5
和 SHA1
,表示使用哪种加密方法。返回加密后的字符串,注意,返回后的字符串是大写
。
示例
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<script runat="server">
void Enc(object sender, EventArgs e)
{
md5Text.Text = FormsAuthentication.HashPasswordForStoringInConfigFile(md5Text.Text, "MD5");
sha1Text.Text = FormsAuthentication.HashPasswordForStoringInConfigFile(sha1Text.Text, "SHA1");
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET 中执行 MD5 和 SHA1 加密</title>
</head>
<body>
<form id="form1" runat="server">
<div>
明文:<asp:TextBox ID="plainText" runat="server"></asp:TextBox>
<asp:Button ID="btn" runat="server" Text="加密" OnClick="Enc" />
</div>
<div>MD5 密文:<asp:TextBox ID="md5Text" runat="server" Width="400"></asp:TextBox></div>
<div>SHA1 密文:<asp:TextBox ID="sha1Text"
相关文档:
C#画线控件的应用实例介绍之前我们要明白在C#中没有画线的控件,这里写了一个,大家分享。共有两个控件分别是画横线和画竖线的,关于怎么画斜线有兴趣的可以做一个大家分享。
C#画线控件之横线
using System;
using System.Collections;
using System.ComponentModel; ......
1.要搞数据库编程必须要懂得配置数据库,有几点要提到:
(1) 默认情况下sql server数据库只允许以windows身份登录(即默认你是该电脑的主人,以这种身份登录可
以对数据库服务器拥有最高权限),你可以开启其SQL SERVER 和 windows混合登录模式(就sql server 2000而
言是在企业管理器里的菜单栏"操作"-"属性"里"安全性" ......
//Socket基本编程
//服务端:
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
Thread mythread ;
Socket socket;
// 清理所有正在使用的资源。
protected override void Dispose( bool disposing )
{
try
{
socket.Close();//释放资源
......
c#改变系统鼠标
---------------------------------------------------------------------------------------------------
using System.Runtime.InteropServices;
[DllImport("User32.DLL")]
public static extern bool SetSystemCursor(IntPtr hcur, uint id);
public const uint OCR_NORMAL = 32512;
publ ......
using System.Windows.Forms;
using SAPFunctionsOCX;
using SAPLogonCtrl;
using SAPTableFactoryCtrl;
namespace SAPFunction
{
public partial class Form1 : Form
{
public Form1()
  ......