Advertisement
Meliodas0_0

Ecrypt

Sep 14th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Web.UI.WebControls;
  3. using System.Security.Cryptography;
  4. using System.Text;
  5.  
  6. namespace JSVirtualKeyboard
  7. {
  8.   public partial class WebForm2 : System.Web.UI.Page
  9.    {
  10.  
  11.     private string Encrypt(string txttoEncrypt)
  12.     {
  13.         string EcriptedData = string.Empty;
  14.         byte[] txt_encode = new byte[txttoEncrypt.Length];
  15.         txt_encode = Encoding.UTF8.GetBytes(txttoEncrypt);
  16.         EcriptedData = Convert.ToBase64String(txt_encode);
  17.         return EcriptedData;
  18.     }
  19.  
  20.     private string Decrypt(string txttoDecrypt)
  21.     {
  22.         UTF8Encoding encode_pwd = new UTF8Encoding();
  23.         string DecryptedData = string.Empty;
  24.         Decoder Decode = encode_pwd.GetDecoder();
  25.         byte[] todecodeByte = Convert.FromBase64String(txttoDecrypt);
  26.         int charCount = Decode.GetCharCount(
  27.                                             todecodeByte,
  28.                                             0,
  29.                                             todecodeByte.Length
  30.                                             );
  31.         char[] decoded_char = new char[charCount];
  32.         Decode.GetChars(todecodeByte, 0, todecodeByte.Length, decoded_char, 0);
  33.         DecryptedData = new String(decoded_char);
  34.         return DecryptedData;
  35.     }
  36.  
  37.     protected void btnencrypt_Click(object sender, EventArgs e)
  38.     {
  39.         TextBox2.Text = Encrypt(TextBox1.Text);
  40.     }
  41.  
  42.     protected void btndecrypt_Click(object sender, EventArgs e)
  43.     {
  44.         TextBox1.Text = Decrypt(TextBox2.Text);
  45.     }
  46.  
  47.   }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement