zoukankan      html  css  js  c++  java
  • 密码加密解密

      /// <summary>
            /// 密码加密
            /// </summary>
            /// <param name="PasswordString">密码</param>
            /// <param name="PasswordFormat">加密类型[SHA1],[MD5]</param>
            /// <returns></returns>
            public static string  EncryptPassword(string PasswordString, string PasswordFormat)
            {
                string encryptPassword = null;
                if (PasswordFormat == "SHA1")
                {
                    encryptPassword =FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordString, "SHA1");
                }
                else if (PasswordFormat == "MD5")
                {
                    encryptPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordString, "MD5");
                }
                return encryptPassword;
            }

      /// <summary>
            /// DES解密字符串
            /// </summary>
            /// <param name="decryptString">待解密的字符串</param>
            /// <param name="decryptKey">解密密钥,要求为8位,和加密密钥相同</param>
            /// <returns>解密成功返回解密后的字符串,失败返源串</returns>
            public static string DecryptDES(string decryptString, string decryptKey)
            {
                try
                {
                    byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey);
                    byte[] rgbIV = Keys;
                    byte[] inputByteArray = Convert.FromBase64String(decryptString);
                    DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
                    MemoryStream mStream = new MemoryStream();
                    CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey,rgbIV), CryptoStreamMode.Write);
                    cStream.Write(inputByteArray, 0, inputByteArray.Length);
                    cStream.FlushFinalBlock();
                    return Encoding.UTF8.GetString(mStream.ToArray());
                }
                catch
                {
                    return decryptString;
                }
            }

  • 相关阅读:
    Consul注销实例
    sql优化基础篇
    linux下执行java类(运行java定时器)
    ExecutorService 的理解与使用
    精度计算的方法
    内部类详解
    接口的作用
    面向对象之继承和组合浅谈
    构造器前篇
    教师编制考试数据分析
  • 原文地址:https://www.cnblogs.com/haofaner/p/3664389.html
Copyright © 2011-2022 走看看