• 大小: 0.11M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-23
  • 语言: C#
  • 标签: 加解密  DES  ES  解密  

资源简介

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个文件信息

评论

共有 条评论