fork(1) download
  1. using System;
  2. using System.IO;
  3. using System.Security.Cryptography;
  4. using System.Text;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var tempData = "This is the text to encrypt. It's not much, but it's all there is.";
  11.  
  12. using (var rijCrypto = new RijndaelManaged())
  13. {
  14. byte[] encryptedData;
  15. rijCrypto.Padding = System.Security.Cryptography.PaddingMode.ISO10126;
  16. rijCrypto.KeySize = 256;
  17.  
  18. using (var input = new MemoryStream(Encoding.Unicode.GetBytes(tempData)))
  19. using (var output = new MemoryStream())
  20. {
  21. var encryptor = rijCrypto.CreateEncryptor();
  22.  
  23. using (var cryptStream = new CryptoStream(output, encryptor, CryptoStreamMode.Write))
  24. {
  25. var buffer = new byte[1024];
  26. var read = input.Read(buffer, 0, buffer.Length);
  27. while (read > 0)
  28. {
  29. cryptStream.Write(buffer, 0, read);
  30. read = input.Read(buffer, 0, buffer.Length);
  31. }
  32. cryptStream.FlushFinalBlock();
  33. encryptedData = output.ToArray();
  34. }
  35. }
  36.  
  37. using (var input = new MemoryStream(encryptedData))
  38. using (var output = new MemoryStream())
  39. {
  40. var decryptor = rijCrypto.CreateDecryptor();
  41. using (var cryptStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read))
  42. {
  43. var buffer = new byte[1024];
  44. var read = cryptStream.Read(buffer, 0, buffer.Length);
  45. while (read > 0)
  46. {
  47. output.Write(buffer, 0, read);
  48. read = cryptStream.Read(buffer, 0, buffer.Length);
  49. }
  50. cryptStream.Flush();
  51. var result = Encoding.Unicode.GetString(output.ToArray());
  52. Console.WriteLine(result);
  53. }
  54. }
  55. }
  56. }
  57. }
Success #stdin #stdout 0.01s 131776KB
stdin
Standard input is empty
stdout
This is the text to encrypt. It's not much, but it's all there is.