博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MD5加密方法
阅读量:5141 次
发布时间:2019-06-13

本文共 1328 字,大约阅读时间需要 4 分钟。

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.IO;

/// <summary>

///MD5 的摘要说明
/// </summary>
public class MD5
{
public MD5()
{
//
//TODO: 在此处添加构造函数逻辑
//
}

// 本地加密密钥(公钥)

//public const string key = "jd74t5aeq234jl0i";
public const string key = "ZopW1Ege62hsTf32";

/// <summary>

/// 用MD5算法加密字符串
/// </summary>
/// <param name="srcString">要加密的字符串</param>
/// <returns>加密后的字符串</returns>
public static string Encrypt(string srcString)
{
srcString = srcString + key;
byte[] b = Encoding.Default.GetBytes(srcString);
b = new MD5CryptoServiceProvider().ComputeHash(b);
string ret = "";
for (int i = 0; i < b.Length; i++)
{
ret += b[i].ToString("x2").ToUpper();
}
return ret;
}

/// <summary>

/// 用MD5算法加密字符串(不带密钥)
/// </summary>
/// <param name="srcString">要加密的字符串</param>
/// <returns>加密后的字符串</returns>
public static string EncryptWithoutKey(string srcString, Encoding _encoding)
{
byte[] b = Encoding.UTF8.GetBytes(srcString);
byte[] a = Encoding.Convert(Encoding.UTF8, _encoding, b);
b = new MD5CryptoServiceProvider().ComputeHash(a);
string ret = "";
for (int i = 0; i < b.Length; i++)
{
ret += b[i].ToString("x2").ToUpper();
}
return ret;
}
}

转载于:https://www.cnblogs.com/taomylife/p/3216910.html

你可能感兴趣的文章