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

    代码
    #region 加密解密

            
    /// <summary>
            
    /// 加密
            
    /// </summary>
            
    /// <param name="Text">加密字符串</param>
            
    /// <returns></returns>
            public static string Encrypt(string Text)
            {
                
    return Encrypt(Text, "shijilianhe2010310");
            }

            
    /// <summary> 
            
    /// 加密数据 
            
    /// </summary> 
            
    /// <param name="Text"></param> 
            
    /// <param name="sKey"></param> 
            
    /// <returns></returns> 
            public static string Encrypt(string Text, string sKey)
            {
                
    try
                {
                    DESCryptoServiceProvider des 
    = new DESCryptoServiceProvider();
                    
    byte[] inputByteArray;
                    inputByteArray 
    = Encoding.Default.GetBytes(Text);
                    des.Key 
    = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(08));
                    des.IV 
    = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(08));
                    System.IO.MemoryStream ms 
    = new System.IO.MemoryStream();
                    CryptoStream cs 
    = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
                    cs.Write(inputByteArray, 
    0, inputByteArray.Length);
                    cs.FlushFinalBlock();
                    StringBuilder ret 
    = new StringBuilder();
                    
    foreach (byte b in ms.ToArray())
                    {
                        ret.AppendFormat(
    "{0:X2}", b);
                    }
                    
    return ret.ToString();
                }
                
    catch (System.NotSupportedException e)
                {
                    
    return "";
                }
                
    catch (System.Security.Cryptography.CryptographicException e1)
                {
                    
    return "";
                }
            }

            
    /// <summary>
            
    /// 解密
            
    /// </summary>
            
    /// <param name="Text">解密字符串</param>
            
    /// <returns></returns>
            public static string Decrypt(string Text)
            {
                
    return Decrypt(Text, "shijilianhe2010310");
            }
            
    /// <summary> 
            
    /// 解密数据 
            
    /// </summary> 
            
    /// <param name="Text"></param> 
            
    /// <param name="sKey"></param> 
            
    /// <returns></returns> 
            public static string Decrypt(string Text, string sKey)
            {
                
    try
                {
                    DESCryptoServiceProvider des 
    = new DESCryptoServiceProvider();
                    
    int len;
                    len 
    = Text.Length / 2;
                    
    byte[] inputByteArray = new byte[len];
                    
    int x, i;
                    
    for (x = 0; x < len; x++)
                    {
                        i 
    = Convert.ToInt32(Text.Substring(x * 22), 16);
                        inputByteArray[x] 
    = (byte)i;
                    }
                    des.Key 
    = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(08));
                    des.IV 
    = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(08));
                    System.IO.MemoryStream ms 
    = new System.IO.MemoryStream();
                    CryptoStream cs 
    = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
                    cs.Write(inputByteArray, 
    0, inputByteArray.Length);
                    cs.FlushFinalBlock();
                    
    return Encoding.Default.GetString(ms.ToArray());
                }
                
    catch (System.NotSupportedException e)
                {
                    
    return "";
                }
                
    catch (System.Security.Cryptography.CryptographicException e1)
                {
                    
    return "";
                }
            }

            
    /// <summary>
            
    /// MD5加密字符串
            
    /// 
            
    /// </summary>
            
    /// <param name="Value"></param>
            
    /// <returns></returns>
            public static string MD5(string Value)
            {
                MD5CryptoServiceProvider md5Hasher 
    = new MD5CryptoServiceProvider();
                
    string Pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Value, "MD5");
                
    return Pwd;
            }

            
    #endregion
  • 相关阅读:
    selennium模块
    urllib模块
    有关爬虫模块
    爬虫_requests_html
    爬虫x_path
    项目上线
    navicat使用 pymysql操作数据库 sql注入及增删改查
    基本查询语句和方法,连表,子查询
    表与表之间的关系
    存储引擎 数据类型
  • 原文地址:https://www.cnblogs.com/di305449473/p/1193297.html
Copyright © 2011-2022 走看看