• Base64加解密


            /// <summary>
            /// 加密
            /// </summary>
            /// <param name="encryptString"></param>
            /// <param name="keys">密钥(8位)</param>
            /// <returns></returns>
            public static string DESEncrypt(string encryptString, string keys)
            {
                using (System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.DESCryptoServiceProvider())
                {
                    byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
                    des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
                    des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    using (System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write))
                    {
                        cs.Write(inputByteArray, 0, inputByteArray.Length);
                        cs.FlushFinalBlock();
                        cs.Close();
                    }
                    string str = Convert.ToBase64String(ms.ToArray());
                    ms.Close();
                    return str;
                }
            }
            /// <summary>
            /// 解密
            /// </summary>
            /// <param name="decryptString"></param>
            /// <param name="keys"></param>
            /// <returns></returns>
            public static string DESDecrypt(string decryptString, string keys)
            {
                if (decryptString == string.Empty)
                {
                    return "";
                }
                if (keys.Length < 8)
                {
                    return "";
                }
                try
                {
                    byte[] inputByteArray = Convert.FromBase64String(decryptString);
                    using (System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.DESCryptoServiceProvider())
                    {
                        des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
                        des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
                        System.IO.MemoryStream ms = new System.IO.MemoryStream();
                        using (System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write))
                        {
                            cs.Write(inputByteArray, 0, inputByteArray.Length);
                            cs.FlushFinalBlock();
                            cs.Close();
                        }
                        string str = Encoding.UTF8.GetString(ms.ToArray());
                        ms.Close();
                        return str;
                    }
                }
                catch
                {
                    return "";
                }
            }
  • 相关阅读:
    scrapy.FormRequest与FormRequest.from_response 的区别
    可迭代对象和生成器
    css选择器
    xlwt写入excel时候的合并单元格
    html form提交的几种方式
    Python decorator 拦截器
    python manage.py makemigrations & migrate
    asianux4.5 环境, 本地yum源,局域网yum源的配置
    mysql基本操作
    sqlite-mysql migrate
  • 原文地址:https://www.cnblogs.com/Shadow3627/p/2984302.html
Copyright © 2020-2023  润新知