• 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);
            }
        }
    }
  • 相关阅读:
    线性方程与行列式
    几何变换
    复数
    矢量
    DRBD 基础及安装
    OpenSSL自签发CA证书chrome浏览器安全访问
    DRBD+Keepalived高可用
    mysql 直接拷贝data 目录下文件还原数据的实现
    Form表单disabled神坑:无法传值到后端
    设置鼠标样式为不可用
  • 原文地址:https://www.cnblogs.com/Jeely/p/11720798.html
Copyright © 2020-2023  润新知