-
-
Save pomarc/029b019fa3b1919be6e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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