加密类
来源:互联网 发布:短融网靠谱吗 知乎 编辑:程序博客网 时间:2024/06/09 12:17
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Security.Cryptography;
using System.Text;
/// <summary>
/// DEcrypto 的摘要说明
/// </summary>
public class DEcrypto
{
public DEcrypto()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Security.Cryptography;
using System.Text;
/// <summary>
/// DEcrypto 的摘要说明
/// </summary>
public class DEcrypto
{
public DEcrypto()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region ==========加密(不可逆)==========
public static string MD5(string text)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] inputText = Encoding.Default.GetBytes(text);
public static string MD5(string text)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] inputText = Encoding.Default.GetBytes(text);
byte[] buffer = md5.ComputeHash(inputText);
md5.Clear();
md5.Clear();
string str = string.Empty;
for (int i = 0; i < buffer.Length; i++)
{
str += buffer[i].ToString("x").PadLeft(2, '0');
}
return str;
}
#endregion
for (int i = 0; i < buffer.Length; i++)
{
str += buffer[i].ToString("x").PadLeft(2, '0');
}
return str;
}
#endregion
#region ==========加密(可逆)==========
public static string Encrypt(string text)
{
return Encrypt(text, "ghiegcge");
}
public static string Encrypt(string text, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inpuText = Encoding.Default.GetBytes(text);
public static string Encrypt(string text)
{
return Encrypt(text, "ghiegcge");
}
public static string Encrypt(string text, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inpuText = Encoding.Default.GetBytes(text);
des.IV = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
des.Key = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
des.Key = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inpuText, 0, inpuText.Length);
cs.FlushFinalBlock();
StringBuilder sb = new StringBuilder();
foreach (byte b in ms.ToArray())
{
sb.AppendFormat("{0:x2}", b);
}
return sb.ToString();
}
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inpuText, 0, inpuText.Length);
cs.FlushFinalBlock();
StringBuilder sb = new StringBuilder();
foreach (byte b in ms.ToArray())
{
sb.AppendFormat("{0:x2}", b);
}
return sb.ToString();
}
#endregion
#region ============解密(可逆)=========
public static string Decrypt(string text)
{
return Decrypt(text, "ghiegcge");
}
#region ============解密(可逆)=========
public static string Decrypt(string text)
{
return Decrypt(text, "ghiegcge");
}
public static string Decrypt(string text, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputText = new byte[text.Length / 2];
int i, x;
for (x = 0; x < text.Length / 2; x++)
{
i = Convert.ToInt32(text.Substring(x * 2, 2), 16);
inputText[x] = (byte)i;
}
des.IV = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
des.Key = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
int i, x;
for (x = 0; x < text.Length / 2; x++)
{
i = Convert.ToInt32(text.Substring(x * 2, 2), 16);
inputText[x] = (byte)i;
}
des.IV = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
des.Key = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(inputText, 0, inputText.Length);
cs.FlushFinalBlock();
cs.FlushFinalBlock();
return Encoding.Default.GetString(ms.ToArray());
}
#endregion
}
#endregion
}
- 加密类
- 加密类
- 加密类
- .NET中的加密类(对称加密)
- C# DES加密字符串加密类模块
- JAVA_MD5加密,SHA-1加密工具类
- android 基础 加密 加密类Cipher
- 通用加密类
- asp 加密 解密 类
- 加密解密类
- VB文本加密类
- 一个文件加密类
- 密码加密类(PermissionBase)
- 加密解密类(C#)
- 密码加密类(PermissionBase)
- md5加密类
- C#加密类
- 字符串加密解密类
- 哇咔咔。。。。。。。。。
- 初读《Unix入门经典》
- 越发地离不了她
- 图解iPhone开发入门教程
- 编译命令
- 加密类
- 【转】 以后别写程序了,65个源码网站奉献给大家
- 【转】男人成熟与不成熟的N个标志
- 图片低分辨率--lowsrc属性
- 【转】傻孩子:如果你还放不下某个人。。。请看看。。。感觉好的...
- 【转】容量单位
- 什么是环比?什么是同比?它们有什么不一样,侧重点不同?
- 序列化
- 无耻