• 加密和解密算法 Asp.net


    1.aspx页面

     1     <div>
     2         <table>
     3             <tr>
     4                 <td>
     5                     <asp:Label ID="Label1" runat="server" Text="字符串" Font-Size="10pt"></asp:Label>
     6                 </td>
     7                 <td>
     8                     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
     9                 </td>
    10             </tr>
    11             <tr>
    12                 <td>
    13                     <asp:Label ID="Label2" runat="server" Text="加密解密" Font-Size="10pt"></asp:Label>
    14                 </td>
    15                 <td>
    16                     <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    17                 </td>
    18             </tr>
    19             <tr>
    20                 <td colspan="2" align="center">
    21                     <asp:Button ID="Button1" runat="server" Text="加密" onclick="Button1_Click" />&nbsp;&nbsp;&nbsp;&nbsp;
    22                     <asp:Button ID="Button2" runat="server" Text="解密" onclick="Button2_Click" />
    23                 </td>
    24             </tr>
    25         </table>
    26     </div>          

    2.cs页面

     1   protected void Button1_Click(object sender, EventArgs e)
     2     {
     3         TextBox2.Text = Encrypt(TextBox1.Text);
     4     }
     5     protected void Button2_Click(object sender, EventArgs e)
     6     {
     7         TextBox2.Text = Decryptor(TextBox2.Text);
     8     }
     9 
    10     private string Encrypt(string s)
    11     {
    12         Encoding ascii = Encoding.ASCII;
    13         string EncryptString;
    14         EncryptString = "";
    15         for (int i = 0; i < s.Length; i++)
    16         {
    17             int j;
    18             byte[] b = new byte[1];
    19             j = Convert.ToInt32(ascii.GetBytes(s[i].ToString())[0]);
    20             j = j + 5;
    21             b[0] = Convert.ToByte(j);
    22             EncryptString = EncryptString + ascii.GetString(b);
    23         }
    24         return EncryptString;
    25     }
    26     private string Decryptor(string s)
    27     {
    28         Encoding ascii = Encoding.ASCII;
    29         string DecryptorString;
    30         DecryptorString = "";
    31         for (int i = 0; i < s.Length; i++)
    32         {
    33             int j;
    34             byte[] b = new byte[1];
    35             j = Convert.ToInt32(ascii.GetBytes(s[i].ToString())[0]);
    36             j = j - 5;
    37             b[0] = Convert.ToByte(j);
    38             DecryptorString = DecryptorString + ascii.GetString(b);
    39         }
    40         return DecryptorString;  41     } 


    乌龟才背着房子过一辈子
  • 相关阅读:
    IOS开发 网络发展史(NSURLProtocol)
    IOS开发 网络发展史(NSURLCach)
    IOS 开发 网络发展史(URLConnection)
    ios 网络开发(CFNetwork)
    MAC安装mysql
    conda 安装常用包
    从必应上拉取图片
    旋转数组中的二分查找
    东北大学 python模拟登录校园网(2019年6月启用新登录模式后)
    Ubuntu 安装Codeblocks
  • 原文地址:https://www.cnblogs.com/Yellowshorts/p/3085486.html
Copyright © 2020-2023  润新知