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);
            }
        }
    }
  • 相关阅读:
    17963 完美数
    17086 字典序的全排列
    17082 两个有序数序列中找第k小(优先做)
    11087 统计逆序对(优先做)
    8594 有重复元素的排列问题(优先做)
    11076 浮点数的分数表达(优先做)
    9715 相邻最大矩形面积
    剑指offer----替换空格
    [IIS][ASP.NET]“拒绝访问临时目录”的解决方法
    windows 2003端口80system进程占用的情况
  • 原文地址:https://www.cnblogs.com/Jeely/p/11720798.html
Copyright © 2011-2022 走看看