Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Security.Cryptography;
  7.  
  8. namespace ConsoleApplication1
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. Console.WriteLine("ADD: ");
  15. //byte[] playtext = Encoding.ASCII.GetBytes(Console.ReadLine());
  16.  
  17. SHA256Managed myHash = new SHA256Managed();
  18. string some_text = "this is an important message";
  19. string some_text1 = Console.ReadLine();
  20. //sign the message
  21. byte[] signature;
  22.  
  23.  
  24.  
  25. RSACryptoServiceProvider myrsa = new RSACryptoServiceProvider(1600);
  26. signature = myrsa.SignData(System.Text.Encoding.ASCII.GetBytes(some_text1), myHash);
  27. bool verified;
  28.  
  29. verified =myrsa.VerifyData(System.Text.Encoding.ASCII.GetBytes(some_text), myHash, signature);
  30.  
  31. Console.Write(" "+verified);
  32.  
  33. System.Diagnostics.Stopwatch swatch = new System.Diagnostics.Stopwatch();
  34. int size;
  35. int count = 100;
  36. swatch.Start();
  37. for (int i = 0; i < count; i++)
  38. {
  39. myrsa = new RSACryptoServiceProvider(1024);
  40. size = myrsa.KeySize;
  41. Console.Write(i + " ");
  42. }
  43. swatch.Stop();
  44. Console.WriteLine("Generation time at 1024 bit ... " +(swatch.ElapsedTicks / (10 * count)).ToString() + " ms");
  45. byte[] plain = new byte[20];
  46. byte[] ciphertext = myrsa.Encrypt(plain, true);
  47. swatch.Reset();
  48. swatch.Start();
  49. for (int i = 0; i < count; i++)
  50. {
  51. ciphertext = myrsa.Encrypt(plain, true);
  52. Console.WriteLine(Encoding.UTF8.GetString(ciphertext, 0, ciphertext.Length) + " ");
  53. }
  54. swatch.Stop();
  55. Console.WriteLine("Encryption time at 1024 bit ... " + (swatch.ElapsedTicks / (10 * count)).ToString() + " ms");
  56. swatch.Reset();
  57. swatch.Start();
  58. for (int i = 0; i < count; i++)
  59. {
  60. plain = myrsa.Decrypt(ciphertext, true);
  61. Console.Write(Encoding.UTF8.GetString(plain, 0, plain.Length) + " ");
  62.  
  63. }
  64. swatch.Stop();
  65. Console.WriteLine("Decryption time at 1024 bit ... " + (swatch.ElapsedTicks / (10 * count)).ToString() + " ms");
  66. Console.ReadKey();
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement