Skip to content

Instantly share code, notes, and snippets.

@pomarc
Created July 31, 2014 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pomarc/029b019fa3b1919be6e1 to your computer and use it in GitHub Desktop.
Save pomarc/029b019fa3b1919be6e1 to your computer and use it in GitHub Desktop.
static double TestAsymmetricPerformances(int numberOfRuns)
{
// First create the keypairs for both Alice and Bob
var Alice = new KeyPair();
var Bob = new KeyPair();
CryptoBox.ComputeKeyPair(Alice.PublicKey, Alice.SecretKey);
CryptoBox.ComputeKeyPair(Bob.PublicKey, Bob.SecretKey);
// Then specify the nonce and fill it with random values
var nonce = new byte[CryptoBox.NonceBytes];
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(nonce);
// Alice sends a message to Bob
var message = "You know nothing Jon Snow!";
DateTime now = DateTime.Now;
//normal operations:
for (int i = 0; i < numberOfRuns; i++)
{
byte[] secretMessage = EncryptAsymmetric(message, Bob.PublicKey, Alice.SecretKey, nonce);
// Bob receives the encrypted message and decrypts it
string decryptedMessage = DecryptAsymmetric(secretMessage, Alice.PublicKey, Bob.SecretKey, nonce);
}
var span = ((TimeSpan)(DateTime.Now - now));
//no totalMillisecons on MF
return span.Minutes * 60 * 1000 + span.Seconds * 1000 + span.Milliseconds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment