常用的加密解密方法
来源:互联网 发布:如何优化行政审批流程 编辑:程序博客网 时间:2024/04/30 13:41
using System;
using System.Security.Cryptography;
using System.Text;
namespace AttendService
{
public static class DESEncrypt
{
#region ========加密========
private static string txtKey = "PatrickpanP=";
private static string txtIV = "LiuJineagel=";
/// <summary>
/// 加密数据
/// </summary>
/// <param name="Text"></param>
/// <param name="sKey"></param>
/// <returns></returns>
public static string Encrypt(string Text)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray;
inputByteArray = Encoding.Default.GetBytes(Text);
//des.Key =ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey,"md5").Substring(0, 8));
//des.IV =ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey,"md5").Substring(0, 8));
des.Key = Convert.FromBase64String(txtKey);
des.IV = Convert.FromBase64String(txtIV);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}", b);
}
return ret.ToString();
}
#endregion
#region ========解密========
/// <summary>
/// 解密数据
/// </summary>
/// <param name="Text"></param>
/// <param name="sKey"></param>
/// <returns></returns>
public static string Decrypt(string Text)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
int len;
len = Text.Length / 2;
byte[] inputByteArray = new byte[len];
int x, i;
for (x = 0; x < len; x++)
{
i = Convert.ToInt32(Text.Substring(x * 2, 2), 16);
inputByteArray[x] = (byte)i;
}
//des.Key =ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey,"md5").Substring(0, 8));
//des.IV =ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey,"md5").Substring(0, 8));
des.Key = Convert.FromBase64String(txtKey);
des.IV = Convert.FromBase64String(txtIV);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Encoding.Default.GetString(ms.ToArray());
}
}
}
- 常用的加密解密方法
- 常用加密解密方法
- 常用加密解密方法
- 常用加密解密方法
- 常用的加密解密方法收藏
- java 常用方法的加密解密
- java常用的加密解密方法
- java常用的加密解密方法
- C#常用的加密解密方法
- 常用的加密和解密方法
- java常用的加密解密方法
- 一些常用的加密解密、编码方法
- C# 常用加密解密方法
- .net常用加密解密方法
- .net常用加密解密方法
- C#中常用的字符串加密,解密方法封装
- 常用的数据加密和解密方法汇总
- Java中常用的加密与解密方法
- PHP图像处理--MagicWand生成缩略图(可加水印)
- MS SQL之多条件动态查询
- 日赚3亿的中移动,喝的是老百姓的血!
- Mysql之EXPLAIN显示using filesort
- 比google和百度牛的十倍的搜索类网站
- 常用的加密解密方法
- ajax省市县联动
- SIP协议概述
- J2EE程序员需掌握的技术
- LINQ视频分享(一)
- 我也说说盗版
- 电子书网站
- 西湖印象
- 计算机串口相连进行通信