• URL参数加密解密过程


      public static string Encode(string str, string key)
     2         {
     3             DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
     4             provider.Key = Encoding.ASCII.GetBytes(key.Substring(08));
     5             provider.IV = Encoding.ASCII.GetBytes(key.Substring(08));
     6             byte[] bytes = Encoding.UTF8.GetBytes(str);
     7             MemoryStream stream = new MemoryStream();
     8             CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);
     9             stream2.Write(bytes, 0, bytes.Length);
    10             stream2.FlushFinalBlock();
    11             StringBuilder builder = new StringBuilder();
    12             foreach (byte num in stream.ToArray())
    13             {
    14                 builder.AppendFormat("{0:X2}", num);
    15             }
    16             stream.Close();
    17             return builder.ToString();
    18         }
    解密代码
     1  public static string Decode(string str, string key)
     2         {
     3             DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
     4             provider.Key = Encoding.ASCII.GetBytes(key.Substring(08));
     5             provider.IV = Encoding.ASCII.GetBytes(key.Substring(08));
     6             byte[] buffer = new byte[str.Length / 2];
     7             for (int i = 0; i < (str.Length / 2); i++)
     8             {
     9                 int num2 = Convert.ToInt32(str.Substring(i * 22), 0x10);
    10                 buffer[i] = (byte)num2;
    11             }
    12             MemoryStream stream = new MemoryStream();
    13             CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write);
    14             stream2.Write(buffer, 0, buffer.Length);
    15             stream2.FlushFinalBlock();
    16             stream.Close();
    17             return Encoding.GetEncoding("GB2312").GetString(stream.ToArray());
    18         } 
    前台
    <p>
            
    <asp:TextBox ID="txtbox" runat="server"></asp:TextBox>
            
    <asp:Button ID="btnok" runat="server" onclick="btnok_Click" Text="加密" />
            
    <asp:Button ID="btncanel" runat="server" Text="解密" onclick="btncanel_Click" />
        
    </p>
    后台代码
     1   protected void btnok_Click(object sender, EventArgs e)
     2         {
     3 
     4             txtbox.Text = Helper.Encode(txtbox.Text.Trim(), "Rainight").Trim();
     5 
     6          
     7 
     8            
     9         }
    10 
    11         protected void btncanel_Click(object sender, EventArgs e)
    12         {
    13             txtbox.Text = Helper.Decode(txtbox.Text.Trim(), "Rainight").Trim();
    14             Response.Write(Helper.Decode(txtbox.Text.Trim(), "Rainight"));
    15         }
  • 相关阅读:
    vmwear 及docker
    vue相关
    vue demo
    线程的死锁
    让出和守护线程
    join加入线程
    线程的优先级
    线程间的通信
    synchronized关键字的使用
    线程的并发
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/1847372.html
Copyright © 2020-2023  润新知