zoukankan      html  css  js  c++  java
  • DES加密解密工具

    using System;
    using System.Text;
    using System.Security.Cryptography;
    using System.IO;
    
    namespace DESPwd
    {
        public class DESUtil
        {
            static DESCryptoServiceProvider des = new DESCryptoServiceProvider();
    
            public static DESCryptoServiceProvider DES
            {
                get { return des; }
            }
            const string EncryptionKey = "诺丽科技";
            const string EncryptionIV = "kell";
            public static string Encoder(string input)
            {
                byte[] SourceData = Encoding.Unicode.GetBytes(input);
                byte[] returnData = null;
                try
                {
                    des.Key = ASCIIEncoding.Unicode.GetBytes(EncryptionKey);
                    des.IV = ASCIIEncoding.Unicode.GetBytes(EncryptionIV);
                    MemoryStream ms = new MemoryStream();
                    CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
                    cs.Write(SourceData, 0, SourceData.Length);
                    cs.FlushFinalBlock();
                    returnData = ms.ToArray();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                return Encoding.Unicode.GetString(returnData);
            }
            public static string Decoder(string input)
            {
                byte[] SourceData = Encoding.Unicode.GetBytes(input);
                byte[] returnData = null;
                try
                {
                    DESCryptoServiceProvider desProvider = new DESCryptoServiceProvider();
                    desProvider.Key = Encoding.Unicode.GetBytes(EncryptionKey);
                    desProvider.IV = Encoding.Unicode.GetBytes(EncryptionIV);
                    MemoryStream ms = new MemoryStream();
                    ICryptoTransform encrypto = desProvider.CreateDecryptor();
                    CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);
                    cs.Write(SourceData, 0, SourceData.Length);
                    cs.FlushFinalBlock();
                    returnData = ms.ToArray();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                return Encoding.Unicode.GetString(returnData);
            }
        }
    }
    using System;
    using System.Windows.Forms;
    
    namespace DESPwd
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button10_Click(object sender, EventArgs e)
            {
                textBox9.Text = DESUtil.Encoder(textBox8.Text);
            }
    
            private void button11_Click(object sender, EventArgs e)
            {
                textBox11.Text = DESUtil.Decoder(textBox9.Text);
            }
        }
    }
  • 相关阅读:
    演示使用Metasploit入侵Windows
    Metasploit的基本使用
    安装使用lynis扫描Linux的安全漏洞
    使用Metasploit收集邮箱信息
    Kali Linux:使用nmap扫描主机
    Kali Linux安装SSH Server
    【转】PHP 无限级分类(递归)
    【转】Mysql only_full_group_by以及其他关于sql_mode原因报错详细解决方案
    ERROR 1366 (HY000): Incorrect string value: 'xADxE5x9BxBDxE9x82...' fo的解决方法
    深入理解HTTP协议
  • 原文地址:https://www.cnblogs.com/Jeely/p/11720798.html
Copyright © 2011-2022 走看看