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.Security.Cryptography;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- RSACryptoServiceProvider myRSA = new RSACryptoServiceProvider(2048);
- AesManaged myAES = new AesManaged();
- byte [] RSAciphertext;
- byte [] plaintext;
- //generate an AES key
- double t0 = DateTime.Now.Ticks;
- for (int i = 0; i < 10; i++)
- {
- myAES.GenerateKey();
- }
- double t00 = DateTime.Now.Ticks - t0;
- Console.WriteLine("Generate time=" + t00/100000);
- //encrypt an AES key with RSA
- double t1 = DateTime.Now.Ticks;
- RSAciphertext = myRSA.Encrypt(myAES.Key,true);
- double t2 = DateTime.Now.Ticks- t1;
- Console.WriteLine("Encrypt time=" + t2/10000);
- //decrypt and recover the AES key
- double t3 = DateTime.Now.Ticks;
- for (int i = 0; i < 100; i++)
- {
- myAES.GenerateKey();
- plaintext = myRSA.Decrypt(RSAciphertext, true);
- }
- double t4 = DateTime.Now.Ticks - t3;
- Console.WriteLine("Decrypt time=" + t4/1000000);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement