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

  • 相关阅读:
    信用卡:银联,VISA,MasterCard
    Syncthing vs BitTorrent Sync
    语言代码
    ATMEL精妙的IRQ中断处理过程
    CAN 总线通信控制芯片SJA1000 的读写
    ARM ® and Thumb ®-2 指令系统
    DeJaVu update history
    74系列的型号
    2007 Audi A4 INSTRUMENT CLUSTER WIRING DIAGRAM
    0-10岁儿童体重、身高参考值
  • 原文地址:https://www.cnblogs.com/haofaner/p/3664389.html
Copyright © 2011-2022 走看看