fork(10) download
  1. using System;
  2. using System.Security.Cryptography;
  3. using System.Text;
  4.  
  5. class EncryptorExample
  6. {
  7. private static string quote =
  8. "Things may come to those who wait, but only the " +
  9. "things left by those who hustle. -- Abraham Lincoln";
  10.  
  11. public static void Main()
  12. {
  13. AesCryptoServiceProvider aesCSP = new AesCryptoServiceProvider();
  14.  
  15. aesCSP.GenerateKey();
  16. aesCSP.GenerateIV();
  17. byte[] encQuote = EncryptString(aesCSP, quote);
  18.  
  19. Console.WriteLine("Encrypted Quote:\n");
  20. Console.WriteLine(Convert.ToBase64String(encQuote));
  21.  
  22. Console.WriteLine("\nDecrypted Quote:\n");
  23. Console.WriteLine(DecryptBytes(aesCSP, encQuote));
  24. }
  25.  
  26. public static byte[] EncryptString(SymmetricAlgorithm symAlg, string inString)
  27. {
  28. byte[] inBlock = UnicodeEncoding.Unicode.GetBytes(inString);
  29. ICryptoTransform xfrm = symAlg.CreateEncryptor();
  30. byte[] outBlock = xfrm.TransformFinalBlock(inBlock, 0, inBlock.Length);
  31.  
  32. return outBlock;
  33. }
  34.  
  35. public static string DecryptBytes(SymmetricAlgorithm symAlg, byte[] inBytes)
  36. {
  37. ICryptoTransform xfrm = symAlg.CreateDecryptor();
  38. byte[] outBlock = xfrm.TransformFinalBlock(inBytes, 0, inBytes.Length);
  39.  
  40. return UnicodeEncoding.Unicode.GetString(outBlock);
  41. }
  42. }
Success #stdin #stdout 0.05s 38232KB
stdin
Standard input is empty
stdout
Encrypted Quote:

sIIvV7ZSHT8VWrxCW6ljmYWWrM7uRz7Xex0uKrrkONP25HkGspoS9eMJ7oMf5YPWvwhgHbUOAFUBmRE5lU/l2Yckhk37GpOUYxxF7MsseCDjSRq9ysqz7vPts3OznT621wCTlPXJD7w86UTPKlfdLnkaiurjOs29VQgwk0+UaQOnfDKay2ueDg6xvmuhNQRQ7bmYGjtTZZWiKx1phwlufDG/KzA6CUtH53/9dp/KOwSOKGILxK9guUlHV4Finsd4+724vE+/tBE31q9jBmqDvQ==

Decrypted Quote:

Things may come to those who wait, but only the things left by those who hustle. -- Abraham Lincoln