zoukankan      html  css  js  c++  java
  • DESC加密解密算法

    using System;
    using System.Text;
    using System.Windows.Forms;
    using System.Security.Cryptography;
    using System.IO;
    using System.Collections;
    
    namespace test
    {
        public partial class frm_DESC : Form
        {
            public frm_DESC()
            {
                InitializeComponent();
            }
    
            public string EncryptDES(string code)
            {
                string str;
                byte[] bytes = Encoding.UTF8.GetBytes(code);
                using (TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider())
                {
                    provider.Key = Encoding.ASCII.GetBytes("6x0017^mM*"p:edx001aacO@jPH9^Px#");
                    provider.IV = Encoding.ASCII.GetBytes("De 63A&*");
                    using (MemoryStream stream = new MemoryStream())
                    {
                        using (CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write))
                        {
                            stream2.Write(bytes, 0, bytes.Length);
                            stream2.FlushFinalBlock();
                        }
                        str = Convert.ToBase64String(stream.ToArray());
                    }
                }
                return str;
            }
    
            public string DecryptDES(string password, string verify)
            {
                string str;
                if (verify != "ZZR")
                {
                    return "";
                }
                byte[] buffer = Convert.FromBase64String(password);
                using (TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider())
                {
                    provider.Key = Encoding.ASCII.GetBytes("6x0017^mM*"p:edx001aacO@jPH9^Px#");
                    provider.IV = Encoding.ASCII.GetBytes("De 63A&*");
                    using (MemoryStream stream = new MemoryStream())
                    {
                        using (CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write))
                        {
                            stream2.Write(buffer, 0, buffer.Length);
                            stream2.FlushFinalBlock();
                            stream2.Close();
                        }
                        str = Encoding.UTF8.GetString(stream.ToArray());
                    }
                }
                return str;
            }
    
            public static string GetEncryptionPwd(string pwd, string number)
            {
                int num;
                pwd = pwd.ToLower();
                string str = "QIAN" + pwd;
                for (num = 0; num < number.Length; num += 2)
                {
                    str = str + number.Substring(num, 1);
                }
                str = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str + "CHUANG", "MD5");
    
                var list = new ArrayList();
                for (num = 0; num < str.Length; num++)
                {
                    list.Add(str.Substring(num, 1));
                }
                list.Reverse();
                str = "";
                for (num = 0; num < list.Count; num++)
                {
                    str = str + list[num];
                }
                return str;
            }
    
            private void btn_Decrypt_Click(object sender, EventArgs e)
            {
                string str = txt_Decrypt.Text.Trim();
                txt_Enctry.Text = DecryptDES(str, "ZZR");
            }
    
            private void btn_Encrypt_Click(object sender, EventArgs e)
            {
                string str = txt_Enctry.Text.Trim();
                txt_Decrypt.Text = EncryptDES(str);
            }
    
            private void btn_MD5_Click(object sender, EventArgs e)
            {
                string number = txt_Number.Text.Trim();
                string pwd = txt_Enctry.Text.Trim();
                txt_Decrypt.Text = GetEncryptionPwd(pwd, number);
            }
        }
    }
  • 相关阅读:
    pom 打包空目录
    pom添加多个源代码目录
    pom文件中的内置变量
    POM文件中的标签及说明
    maven 中的内置变量
    maven 的几个重要的配置文件:super pom & 生命周期默认绑定的配置文件
    maven 默认的阶段绑定周期(Plugin Bindings for default Lifecycle Reference)
    maven 生命周期参考(Lifecycles Reference)
    maven编译项目
    cygwin 中文乱码
  • 原文地址:https://www.cnblogs.com/Jeely/p/11720767.html
Copyright © 2011-2022 走看看