资源简介
C#写的一个DESC加密测试,可直接运行,注释清楚,代码简单。另外C#还有几种其他加密方式,如MD5不可逆加密,对称加密等,有兴趣可取看看,简单

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 加密
{
public partial class Form1 : Form
{
public const string Key = “mallpark“;
public Form1()
{
InitializeComponent();
}
///
/// 加密
///
///
///
private void btnEn_Click(object sender EventArgs e)
{
txtDE.Text = Encrypt(txtEN.Text Key);
}
///
/// 解密
///
///
///
private void button1_Click(object sender EventArgs e)
{
txtDE.Text = Decrypt(txtEN.Text Key);
}
///
/// 进行DES加密。
///
/// 要加密的字符串。
/// 密钥,且必须为8位。
/// 以base64格式返回的加密字符串。
string Encrypt(string pToEncrypt string sKey)
{
if (pToEncrypt == ““)
return ““;
try
{
using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
{
byte[] inputByteArray = Encoding.UTF8.GetBytes(pToEncrypt);
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
using (CryptoStream cs = new CryptoStream(ms des.CreateEncryptor() CryptoStreamMode.Write))
{
cs.Write(inputByteArray 0 inputByteArray.Length);
cs.FlushFinalBlock();
cs.Close();
}
string str = Convert.Tobase64String(ms.ToArray());
ms.Close();
return str;
}
}
catch
{
return “该字符串无法加密“;
}
}
///
/// 进行DES解密。
///
/// 要解密的以base64
/// 密钥,且必须为8位。
/// 已解密的字符串。
string Decrypt(string pToDecrypt string sKey)
{
if (pToDecrypt == ““)
return ““;
try
{
using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
{
byte[] inputByteArray = Convert.Frombase64String(pToDecrypt);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 167 2018-12-27 03:31 加密\App.config
目录 0 2018-12-27 03:35 加密\bin\
文件 3985 2018-12-27 03:31 加密\Form1.cs
文件 4626 2018-12-27 03:31 加密\Form1.Designer.cs
文件 5817 2018-12-27 03:31 加密\Form1.resx
目录 0 2018-12-27 03:31 加密\obj\
目录 0 2018-12-27 03:32 加密\obj\Debug\
文件 865 2018-12-27 03:32 加密\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6825 2018-12-27 03:32 加密\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
目录 0 2018-12-27 03:32 加密\obj\Debug\TempPE\
文件 4608 2018-12-27 03:32 加密\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
文件 1185 2018-12-27 03:34 加密\obj\Debug\加解密.csproj.FileListAbsolute.txt
文件 977 2018-12-27 03:32 加密\obj\Debug\加解密.csproj.GenerateResource.Cache
文件 2211 2018-12-27 03:32 加密\obj\Debug\加解密.csprojResolveAssemblyReference.cache
文件 10752 2018-12-27 03:32 加密\obj\Debug\加密.exe
文件 180 2018-12-27 03:31 加密\obj\Debug\加密.Form1.resources
文件 28160 2018-12-27 03:32 加密\obj\Debug\加密.pdb
文件 180 2018-12-27 03:31 加密\obj\Debug\加密.Properties.Resources.resources
文件 518 2018-12-27 03:31 加密\Program.cs
目录 0 2018-12-27 03:31 加密\Properties\
文件 1350 2018-12-27 03:31 加密\Properties\AssemblyInfo.cs
文件 2852 2018-12-27 03:31 加密\Properties\Resources.Designer.cs
文件 5612 2018-12-27 03:31 加密\Properties\Resources.resx
文件 1106 2018-12-27 03:31 加密\Properties\Settings.Designer.cs
文件 249 2018-12-27 03:31 加密\Properties\Settings.settings
文件 3857 2018-12-27 03:31 加密\加解密.csproj
文件 3584 2018-12-27 03:35 加密\加解密.v12.suo
- 上一篇:串口扫描枪 c# 最简程序源码
- 下一篇:FTP课程设计(服务端+客户端) 源码
相关资源
- C# IP地址输入控件
- C#在一个窗口刷新更改另一个窗口控件
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
评论
共有 条评论