Advertisement
alexarcan

CS_Crypto_Seminary1

Dec 7th, 2016
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Security.Cryptography;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. RSACryptoServiceProvider myRSA = new RSACryptoServiceProvider(2048);
  15.  
  16. AesManaged myAES = new AesManaged();
  17. byte [] RSAciphertext;
  18. byte [] plaintext;
  19. //generate an AES key
  20. double t0 = DateTime.Now.Ticks;
  21. for (int i = 0; i < 10; i++)
  22. {
  23. myAES.GenerateKey();
  24. }
  25. double t00 = DateTime.Now.Ticks - t0;
  26. Console.WriteLine("Generate time=" + t00/100000);
  27. //encrypt an AES key with RSA
  28. double t1 = DateTime.Now.Ticks;
  29. RSAciphertext = myRSA.Encrypt(myAES.Key,true);
  30. double t2 = DateTime.Now.Ticks- t1;
  31. Console.WriteLine("Encrypt time=" + t2/10000);
  32. //decrypt and recover the AES key
  33. double t3 = DateTime.Now.Ticks;
  34. for (int i = 0; i < 100; i++)
  35. {
  36. myAES.GenerateKey();
  37. plaintext = myRSA.Decrypt(RSAciphertext, true);
  38. }
  39. double t4 = DateTime.Now.Ticks - t3;
  40. Console.WriteLine("Decrypt time=" + t4/1000000);
  41. Console.ReadLine();
  42.  
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement