• 密码加密解密


      /// <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;
                }
            }

  • 相关阅读:
    C/C++打印堆栈信息
    adb shell input keyevent值所对应的字符
    Nautilus-Share-Message: Called "net usershare info" but it failed: Failed to
    ubuntu 安装lua错误
    ubuntu 16.04 安装jdk9错误
    国家统计信息查询网址
    Spring ApplicationListener配合-D实现参数初始化
    Feign Form表单POST提交
    window下绝对路径
    SpringBoot中使用配置文件
  • 原文地址:https://www.cnblogs.com/haofaner/p/3664389.html
Copyright © 2020-2023  润新知