資源簡介
AVI,SVI文件互轉,Des 加解密
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Security.Cryptography;
using?System.IO;
namespace?DesCrypto
{
????public?class?DESSecurity
????{
????????///?
????????///?DES?加密過程
????????///?
????????///?待加密數據
????????///?
????????///?
????????public?byte[]?Encrypt(byte[]?dataToEncrypt?char[]?DESKeychar[]?DESIV)
????????{
????????????using?(DESCryptoServiceProvider?des?=?new?DESCryptoServiceProvider())
????????????{
????????????????int?i?=?0;
????????????????des.Key?=?ASCIIEncoding.ASCII.GetBytes(DESKey);?//建立加密對象的密鑰和偏移量
????????????????des.IV?=?ASCIIEncoding.ASCII.GetBytes(DESIV);
????????????????des.Padding?=?PaddingMode.Zeros;
????????????????using?(MemoryStream?ms?=?new?MemoryStream())
????????????????{
????????????????????using?(CryptoStream?cs?=?new?CryptoStream(ms?des.CreateEncryptor()?CryptoStreamMode.Write))
????????????????????{
????????????????????????cs.Write(dataToEncrypt?0?dataToEncrypt.Length);
????????????????????????cs.FlushFinalBlock();
????????????????????????StringBuilder?ret?=?new?StringBuilder();
????????????????????????byte[]?data?=?new?byte[ms.ToArray().Length];
????????????????????????foreach?(byte?b?in?ms.ToArray())
????????????????????????{
????????????????????????????data[i++]?=?b;
????????????????????????????//ret.AppendFormat(“{0:x2}“?b);
????????????????????????}
????????????????????????
????????????????????????return?data;
????????????????????}
????????????????}
????????????}
????????}
????????///?
????????///?DES?解密過程
????????///?
????????///?待解密數據
????????///?
????????///?
????????public?byte[]?Decrypt(byte[]?dataToDecrypt?char[]?DESKeychar[]?DESIV)
????????{?????????????????
????????????using?(DESCryptoServiceProvider?des?=?new?DESCryptoServiceProvider())
????????????{
????????????????des.Key?=?ASCIIEncoding.ASCII.GetBytes(DESKey);?//建立加密對象的密鑰和偏移量,此值重要,不能修改
????????????????des.IV?=?ASCIIEncoding.ASCII.GetBytes(DESIV);
????????????????des.Padding?=?PaddingMode.Zeros;
????????????????int?i?=?0;
????????????????using?(MemoryStream?ms?=?new?MemoryStream())
????????????????{
????????????????????using?(CryptoStream?cs?=?new?CryptoStream(ms?des.CreateDecryptor()?CryptoStreamMode.Write))
????????????????????{
????????????????????????cs.Write(dataToDecrypt?0?dataToDecrypt.Length);
????????????????????????cs.FlushFinalBlock();
????????????????????????byte[]?data?=?new?byte[ms.ToArray().Length];
????????????????????????foreach?(byte?b?in?ms.ToArray())
????????????????????????{
????????????????????????????data[i++]?=?b;
????????????????????????????//ret.AppendFormat(“{0:x2}“?b);
????????????????????????}
????????????????????????return?data;
????????????????????}
????????????????}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-05-11?13:28??DesCrypto\
?????目錄???????????0??2018-07-06?14:09??DesCrypto\DesCrypto\
?????文件?????????996??2018-05-10?08:38??DesCrypto\DesCrypto.sln
?????文件???????60928??2018-07-06?17:04??DesCrypto\DesCrypto.v12.suo
?????文件?????????187??2018-05-10?08:38??DesCrypto\DesCrypto\App.config
?????目錄???????????0??2018-05-11?13:28??DesCrypto\DesCrypto\bin\
?????目錄???????????0??2018-05-11?13:28??DesCrypto\DesCrypto\bin\Debug\
?????文件???????17408??2018-05-11?13:27??DesCrypto\DesCrypto\bin\Debug\DesCrypto.exe
?????文件?????????187??2018-05-10?08:38??DesCrypto\DesCrypto\bin\Debug\DesCrypto.exe.config
?????文件???????34304??2018-05-11?13:27??DesCrypto\DesCrypto\bin\Debug\DesCrypto.pdb
?????文件???????24224??2018-05-11?13:30??DesCrypto\DesCrypto\bin\Debug\DesCrypto.vshost.exe
?????文件?????????187??2018-05-10?08:38??DesCrypto\DesCrypto\bin\Debug\DesCrypto.vshost.exe.config
?????文件?????????490??2015-10-30?15:19??DesCrypto\DesCrypto\bin\Debug\DesCrypto.vshost.exe.manifest
?????目錄???????????0??2018-07-06?14:15??DesCrypto\DesCrypto\bin\Release\
?????文件???????16896??2018-07-06?14:10??DesCrypto\DesCrypto\bin\Release\DesCrypto.exe
?????文件?????????187??2018-05-10?08:38??DesCrypto\DesCrypto\bin\Release\DesCrypto.exe.config
?????文件???????32256??2018-07-06?14:10??DesCrypto\DesCrypto\bin\Release\DesCrypto.pdb
?????文件???????24224??2018-07-06?14:14??DesCrypto\DesCrypto\bin\Release\DesCrypto.vshost.exe
?????文件?????????187??2018-05-10?08:38??DesCrypto\DesCrypto\bin\Release\DesCrypto.vshost.exe.config
?????文件?????????490??2015-10-30?15:19??DesCrypto\DesCrypto\bin\Release\DesCrypto.vshost.exe.manifest
?????文件????????3855??2018-05-10?10:53??DesCrypto\DesCrypto\DesCrypto.csproj
?????文件????????3148??2018-05-11?13:27??DesCrypto\DesCrypto\DESSecurity.cs
?????文件???????15169??2018-07-06?14:09??DesCrypto\DesCrypto\MainForm.cs
?????文件????????8210??2018-05-11?09:30??DesCrypto\DesCrypto\MainForm.Designer.cs
?????文件????????5817??2018-05-11?09:30??DesCrypto\DesCrypto\MainForm.resx
?????目錄???????????0??2018-05-11?13:30??DesCrypto\DesCrypto\obj\
?????目錄???????????0??2018-05-11?13:28??DesCrypto\DesCrypto\obj\Debug\
?????文件?????????861??2018-05-11?13:30??DesCrypto\DesCrypto\obj\Debug\DesCrypto.csproj.FileListAbsolute.txt
?????文件?????????980??2018-05-11?13:27??DesCrypto\DesCrypto\obj\Debug\DesCrypto.csproj.GenerateResource.Cache
?????文件???????17408??2018-05-11?13:27??DesCrypto\DesCrypto\obj\Debug\DesCrypto.exe
?????文件?????????180??2018-05-11?13:27??DesCrypto\DesCrypto\obj\Debug\DesCrypto.MainForm.resources
............此處省略28個文件信息
- 上一篇:linq學習
- 下一篇:輪詢RabbitMQ消息隊列
評論
共有 條評論