Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. private static RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
  2.         public static string IV = "mvi4j0r32sdf4gj8"; // 16 chars = 128 bits
  3.         public static string Key = "h564j9z4j5h4j6z48g68h4j8gz84jz8g"; // 32 chars = 256 bits
  4.         byte[] IVrandom = new byte[16];
  5.  
  6.  
  7.         public static string Encrypt(string decrypted)
  8.         {
  9.             byte[] IVrandom = new byte[16];
  10.  
  11.             byte[] textbytes = ASCIIEncoding.ASCII.GetBytes(decrypted);
  12.             AesCryptoServiceProvider encdec = new AesCryptoServiceProvider();
  13.             encdec.BlockSize = 128;
  14.             encdec.KeySize = 256;
  15.             encdec.Key = ASCIIEncoding.ASCII.GetBytes(Key);
  16.             encdec.IV = ASCIIEncoding.ASCII.GetBytes(IV);
  17.             encdec.Padding = PaddingMode.PKCS7;
  18.             encdec.Mode = CipherMode.CBC;
  19.  
  20.             ICryptoTransform icrypt = encdec.CreateEncryptor(encdec.Key, encdec.IV);
  21.  
  22.             byte[] enc = icrypt.TransformFinalBlock(textbytes, 0, textbytes.Length);
  23.             icrypt.Dispose();
  24.  
  25.             return Convert.ToBase64String(enc);
  26.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement