//加密
public string DesEncrypt(string strText, string strEncrKey)
{
byte[] byKey=null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0,8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray =System.Text.Encoding.UTF8.GetBytes(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write) ;
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch(System.Exception error)
{
MessageBox.Show(error.Message);
return "error:" +error.Message+"/r";
}
} //解密
public string DesDecrypt(string strText,string sDecrKey)
{
byte[] byKey = null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
byte[] inputByteArray = new Byte[strText.Length];
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0,8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
return encoding.GetString(ms.ToArray());
}
catch(System.Exception error)
{
MessageBox.Show(error.Message);
return "error:"+error.Message+"/r";
}
}编辑推荐:
- 一段asp.net DES加密解密的代码02-21
- 解析DataBinder_Eval的用法02-21
- windows10系统激活技巧 win10激活有效方法攻略02-21
- 详细介绍ASP.NET中的C#基础知识02-21
- C#中常用的正则表达式总结分享02-21
- 在ASP.NET中上传下载文件实例代码02-21
- C#如何使用正则表达式抓取网站信息的代码案例02-21
- C#正则函数匹配、替换、提取的用法代码分享02-21
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- 一段asp.net DES加密解密的代码
一段asp.net DES加密解密的代码
26-02-21 - 解析DataBinder_Eval的用法
解析DataBinder_Eval的用法
26-02-21 - windows10系统激活技巧 win10激活有效方法攻略
windows10系统激活技巧 win10激活有效方法攻略
26-02-21 - C#网络编程的图文代码详解
C#网络编程的图文代码详解
26-02-21 - C#添加Windows服务定时任务的图文代码解析
C#添加Windows服务定时任务的图文代码解析
26-02-21 - C#从枚举值获取对应文本的图文代码详解
C#从枚举值获取对应文本的图文代码详解
26-02-21 - 详细了解在.NET Core 上运行的WordPress
详细了解在.NET Core 上运行的WordPress
26-02-21 - C#使用Selenium+PhantomJS抓取数据详解
C#使用Selenium+PhantomJS抓取数据详解
26-02-21 - ASP.NET数据绑定控件详解(图文)
ASP.NET数据绑定控件详解(图文)
26-02-21 - 详解C#创建dll类库的方法分享(图文)
详解C#创建dll类库的方法分享(图文)
26-02-21
