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);
            }
        }
    }
  • 相关阅读:
    工作笔记总结——数据库
    PHP 的本地文件缓存处理类(非常高效)
    word如何去掉背景色
    安装CORBA产品visibroker注意问题
    [Python小菜]Bulidin Function Type使用小记
    java正则表达式和网页爬虫的制作
    工作笔记总结——前台js和jQuery
    thinkphp+ajax 实现点击加载更多数据
    第三方微信登录
    substring() 方法用于提取字符串中介于两个指定下标之间的字符。
  • 原文地址:https://www.cnblogs.com/Jeely/p/11720798.html
Copyright © 2011-2022 走看看