zoukankan      html  css  js  c++  java
  • 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 "";
                }
            }
  • 相关阅读:
    uboot编译配置过程
    APUE-数据库函数库
    值得推荐的C/C++框架和库 (真的很强大)
    ubuntu12.04图形界面与命令行界面切换
    ubuntu14.04 升级gcc的方法
    4. H5+css3
    3,css 内容
    2. 浏览器兼容性问题
    1,http协议
    页面添加水印
  • 原文地址:https://www.cnblogs.com/Shadow3627/p/2984302.html
Copyright © 2011-2022 走看看