Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Security.Cryptography;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("ADD: ");
- //byte[] playtext = Encoding.ASCII.GetBytes(Console.ReadLine());
- SHA256Managed myHash = new SHA256Managed();
- string some_text = "this is an important message";
- string some_text1 = Console.ReadLine();
- //sign the message
- byte[] signature;
- RSACryptoServiceProvider myrsa = new RSACryptoServiceProvider(1600);
- signature = myrsa.SignData(System.Text.Encoding.ASCII.GetBytes(some_text1), myHash);
- bool verified;
- verified =myrsa.VerifyData(System.Text.Encoding.ASCII.GetBytes(some_text), myHash, signature);
- Console.Write(" "+verified);
- System.Diagnostics.Stopwatch swatch = new System.Diagnostics.Stopwatch();
- int size;
- int count = 100;
- swatch.Start();
- for (int i = 0; i < count; i++)
- {
- myrsa = new RSACryptoServiceProvider(1024);
- size = myrsa.KeySize;
- Console.Write(i + " ");
- }
- swatch.Stop();
- Console.WriteLine("Generation time at 1024 bit ... " +(swatch.ElapsedTicks / (10 * count)).ToString() + " ms");
- byte[] plain = new byte[20];
- byte[] ciphertext = myrsa.Encrypt(plain, true);
- swatch.Reset();
- swatch.Start();
- for (int i = 0; i < count; i++)
- {
- ciphertext = myrsa.Encrypt(plain, true);
- Console.WriteLine(Encoding.UTF8.GetString(ciphertext, 0, ciphertext.Length) + " ");
- }
- swatch.Stop();
- Console.WriteLine("Encryption time at 1024 bit ... " + (swatch.ElapsedTicks / (10 * count)).ToString() + " ms");
- swatch.Reset();
- swatch.Start();
- for (int i = 0; i < count; i++)
- {
- plain = myrsa.Decrypt(ciphertext, true);
- Console.Write(Encoding.UTF8.GetString(plain, 0, plain.Length) + " ");
- }
- swatch.Stop();
- Console.WriteLine("Decryption time at 1024 bit ... " + (swatch.ElapsedTicks / (10 * count)).ToString() + " ms");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement