Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Security.Cryptography;
  4. using System.Text;
  5.  
  6. public class Program
  7. {
  8. public static void Main()
  9. {
  10. DecryptString("BQO5l5Kj9MdErXx6Q6AGOw==", "c4scadek3y654321");
  11. }
  12.  
  13. public static string EncryptString(string Plaintext, string Key)
  14. {
  15. byte[] bytes = Encoding.UTF8.GetBytes(Plaintext);
  16. Aes aes = Aes.Create();
  17. aes.BlockSize = 128;
  18. aes.KeySize = 128;
  19. aes.IV = Encoding.UTF8.GetBytes("1tdyjCbY1Ix49842");
  20. aes.Key = Encoding.UTF8.GetBytes(Key);
  21. aes.Mode = CipherMode.CBC;
  22. string result;
  23. using (MemoryStream memoryStream = new MemoryStream())
  24. {
  25. using (CryptoStream cryptoStream = new CryptoStream(memoryStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
  26. {
  27. cryptoStream.Write(bytes, 0, bytes.Length);
  28. cryptoStream.FlushFinalBlock();
  29. }
  30. result = Convert.ToBase64String(memoryStream.ToArray());
  31. }
  32. return result;
  33. }
  34.  
  35. public static string DecryptString(string EncryptedString, string Key)
  36. {
  37. byte[] array = Convert.FromBase64String(EncryptedString);
  38. Aes aes = Aes.Create();
  39. aes.KeySize = 128;
  40. aes.BlockSize = 128;
  41. aes.IV = Encoding.UTF8.GetBytes("1tdyjCbY1Ix49842");
  42. aes.Mode = CipherMode.CBC;
  43. aes.Key = Encoding.UTF8.GetBytes(Key);
  44. string @string;
  45. using (MemoryStream memoryStream = new MemoryStream(array))
  46. {
  47. using (CryptoStream cryptoStream = new CryptoStream(memoryStream, aes.CreateDecryptor(), CryptoStreamMode.Read))
  48. {
  49. byte[] array2 = new byte[checked(array.Length - 1 + 1)];
  50. cryptoStream.Read(array2, 0, array2.Length);
  51. @string = Encoding.UTF8.GetString(array2);
  52. }
  53. }
  54. Console.WriteLine(@string);
  55. return @string;
  56. }
  57.  
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement