利用下面的方法,可直接输入数据,反回md5加密后的代码

/// <summary>
/// 用md5加密
/// </summary>
/// <param name="Sourcein">输入的数据</param>
/// <returns></returns>
public static string MD5(string Sourcein)
{
   MD5CryptoServiceProvider MD5CSP = new MD5CryptoServiceProvider();
   byte[] MD5Source = System.Text.Encoding.UTF8.GetBytes(Sourcein);
   byte[] MD5Out = MD5CSP.ComputeHash(MD5Source);
   return Convert.ToBase64String(MD5Out);
}

以上只是适用于.net的MD5加密,但是现在很多公司处于asp转asp.net的阶段,为了不改动原来的教大的用户数据库,我们需要找到一种跟asp的md5加密后相同的结果,下面的代码是我曾经用过的,给出来大家参考:黄色部分代码

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication2
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.TextBox textBox1;
  private System.Windows.Forms.TextBox textBox2;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label2;
  private System.Windows.Forms.TextBox textBox3;
  private System.Windows.Forms.Label label3;
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;

public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

//
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

/// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

#region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.button1 = new System.Windows.Forms.Button();
   this.textBox1 = new System.Windows.Forms.TextBox();
   this.textBox2 = new System.Windows.Forms.TextBox();
   this.label1 = new System.Windows.Forms.Label();
   this.label2 = new System.Windows.Forms.Label();
   this.textBox3 = new System.Windows.Forms.TextBox();
   this.label3 = new System.Windows.Forms.Label();
   this.SuspendLayout();
   //
   // button1
   //
   this.button1.Location = new System.Drawing.Point(200, 96);
   this.button1.Name = "button1";
   this.button1.TabIndex = 0;
   this.button1.Text = "加密";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // textBox1
   //
   this.textBox1.Location = new System.Drawing.Point(88, 24);
   this.textBox1.Name = "textBox1";
   this.textBox1.Size = new System.Drawing.Size(120, 21);
   this.textBox1.TabIndex = 1;
   this.textBox1.Text = "";
   //
   // textBox2
   //
   this.textBox2.Location = new System.Drawing.Point(88, 64);
   this.textBox2.Name = "textBox2";
   this.textBox2.Size = new System.Drawing.Size(312, 21);
   this.textBox2.TabIndex = 2;
   this.textBox2.Text = "";
   //
   // label1
   //
   this.label1.Location = new System.Drawing.Point(48, 32);
   this.label1.Name = "label1";
   this.label1.Size = new System.Drawing.Size(32, 16);
   this.label1.TabIndex = 3;
   this.label1.Text = "密码";
   //
   // label2
   //
   this.label2.Location = new System.Drawing.Point(16, 64);
   this.label2.Name = "label2";
   this.label2.Size = new System.Drawing.Size(64, 16);
   this.label2.TabIndex = 4;
   this.label2.Text = "md5加密后";
   //
   // textBox3
   //
   this.textBox3.Location = new System.Drawing.Point(280, 24);
   this.textBox3.Name = "textBox3";
   this.textBox3.Size = new System.Drawing.Size(120, 21);
   this.textBox3.TabIndex = 5;
   this.textBox3.Text = "";
   //
   // label3
   //
   this.label3.Location = new System.Drawing.Point(216, 32);
   this.label3.Name = "label3";
   this.label3.Size = new System.Drawing.Size(48, 16);
   this.label3.TabIndex = 6;
   this.label3.Text = "偏移量";
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(416, 133);
   this.Controls.Add(this.label3);
   this.Controls.Add(this.textBox3);
   this.Controls.Add(this.label2);
   this.Controls.Add(this.label1);
   this.Controls.Add(this.textBox2);
   this.Controls.Add(this.textBox1);
   this.Controls.Add(this.button1);
   this.Name = "Form1";
   this.Text = "Form1";
   this.Load += new System.EventHandler(this.Form1_Load);
   this.ResumeLayout(false);

}
  #endregion

/// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

/// <summary>
  /// 
  /// </summary>
  /// <param name="sDataIn">需要加密的字符串</param>
  /// <param name="move">偏移量</param>
  /// <returns>sDataIn加密后的字符串</returns>

public string GetMD5(string sDataIn,string move)
  {
   System.Security.Cryptography.MD5CryptoServiceProvider md5=new System.Security.Cryptography.MD5CryptoServiceProvider();
   byte[]bytValue,bytHash;
   bytValue = System.Text.Encoding.UTF8.GetBytes(move+sDataIn);
   bytHash = md5.ComputeHash(bytValue);
   md5.Clear();
   string sTemp="";
   for(int i=0;i<bytHash.Length;i++)
   {
    sTemp+=bytHash[i].ToString("x").PadLeft(2,'0');
   }
   return sTemp;
  }
  private void Form1_Load(object sender, System.EventArgs e)
  {
  
  }

private void button1_Click(object sender, System.EventArgs e)
  {
    this.textBox2.Text = GetMD5(this.textBox1.Text,this.textBox3.Text);
  }
 }
}

转载于:https://www.cnblogs.com/sikezx/archive/2008/08/02/1258525.html

asp.net MD5加密函数(c#)相关推荐

  1. oracle中md5加密解密_Oracle定义DES加密解密及MD5加密函数示例

    (1)DES加密函数 create or replace function encrypt_des(p_text varchar2, p_key varchar2) return varchar2 i ...

  2. VB 字符串MD5加密函数

    函数代码: Private Const BITS_TO_A_BYTE = 8 Private Const BYTES_TO_A_WORD = 4 Private Const BITS_TO_A_WOR ...

  3. php中md5加密函数怎么用,php中md5()函数的定义和用法汇总

    PHP加密函数-md5()函数加密什么是MD5()函数?MD5()函数是计算器字符串的 MD5散列值,使用MD5的算法,MD5的全称是Message-Digest Algorithm 5,它的作用是把 ...

  4. ASP标准MD5加密签名函数代码

    调用示例: <!--#include file="./md5.asp"--> <% sign = MD5(str,"utf-8") '编码方式 ...

  5. ASP使用MD5加密

    1. md5.asp文件 <% ''''''''''''''''''''''''''''''''''''''''''''''''' ' <p>Title: </p>    ...

  6. php中md5加密函数怎么用,PHP加密函数—md5()函数加密实例用法

    PHP加密函数-md5()函数加密 什么是MD5()函数? MD5()函数是计算器字符串的 MD5散列值,使用MD5的算法,MD5的全称是Message-Digest Algorithm 5,它的作用 ...

  7. asp.net MD5 加密

    //Md5摘要 string resultMD5 = FormsAuthentication.HashPasswordForStoringInConfigFile("要加密的内容" ...

  8. php中md5加密函数怎么用,用PHP写的MD5加密函数

    以下为引用的内容: //PHP_md5("字符串") define("BITS_TO_A_BYTE",8); define("BYTES_TO_A_W ...

  9. ASP.Net中MD5加密-16位32位

    public string md5(string str,int code) { if(code==16) //16位MD5加密(取32位加密的9~25字符) { return System.Web. ...

最新文章

  1. 通达信四色谱四量图源码_翔博精选指标熊市专用优化(通达信公式 选股 源码 测试图)...
  2. Cocos Creator学习目录
  3. sudo密码一直出错
  4. threejs坐标转换
  5. JSP——Web应用
  6. mcp证书有什么用_初级会计职称有什么用?考下证书可以做什么工作?
  7. xshell连接虚拟机(后续)
  8. git学习笔记-(3-linux基本命令)
  9. 推荐5款好用的Java软件,初学者必看
  10. usb计算机连接 不再弹出,电脑usb无法安全弹出问题解决办法
  11. windows无法格式化u盘_如何解决u盘0字节无法格式化的问题
  12. Spring —— Spring 手册官网下载地址
  13. Android 开发挑战赛 | 第 2 周: 倒计时器
  14. qt 调用linux键盘输入,嵌入式linux上QT标准键盘输入的实现
  15. Java写的第一个小游戏
  16. java.substr_Java语言中substr和substring的区别
  17. GUI 图形用户界面编程(十一)-扑克界面设计
  18. 如何利用起家里的旧电脑当个人网盘使?这里有半小时教程(逐步)
  19. Oracle静默安装报错
  20. 七年级下册信息技术认识计算机硬件,七年级信息技术下册

热门文章

  1. linux驱动程序混合架构,嵌入式系统最小驱动框架(类似linux驱动程序架构)(示例代码)...
  2. python cnn识别图像_笨方法学习CNN图像识别(一)—— 图片预处理
  3. 《MySQL——幻读与next-key lock与间隙锁带来的死锁》
  4. envs\TensorFlow2.0\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning 解决方案
  5. Leetcode226. 翻转二叉树(递归、迭代、层序三种解法)
  6. Java Date toString()方法与示例
  7. 常用汇编浮点操作指令
  8. MySQL 纯insert_MySQL使用INSERT插入多条记录
  9. 如何在centos中找到安装mysql_centos上如何安装mysql
  10. 软件工程---3.敏捷软件开发