public void Test_Encrypt_Ballot_Simple_Succeeds() { // Configure the election context var keypair = ElGamalKeyPair.FromSecret(Constants.TWO_MOD_Q); var description = new Manifest(manifest_json); var manifest = new InternalManifest(description); var context = new CiphertextElectionContext( 1UL, 1UL, keypair.PublicKey, Constants.TWO_MOD_Q, manifest.ManifestHash); var device = new EncryptionDevice(12345UL, 23456UL, 34567UL, "Location"); var mediator = new EncryptionMediator(manifest, context, device); var ballot = new PlaintextBallot(plaintext_json); // Act var ciphertext = mediator.Encrypt(ballot); // Assert // a property Assert.That(ciphertext.ObjectId == ballot.ObjectId); // json serialization var json = ciphertext.Json; var fromJson = new CiphertextBallot(json); Assert.That(ciphertext.ObjectId == fromJson.ObjectId); // binary serialization var bson = ciphertext.Bson; var fromBson = CiphertextBallot.FromBson(bson); Assert.That(ciphertext.ObjectId == fromBson.ObjectId); // submitted ballot var submitted = SubmittedBallot.From(ciphertext, BallotBoxState.cast); Assert.That(ciphertext.ObjectId == submitted.ObjectId); }
public void Test_Elgamal_Encrypt_Simple() { // Arrange var nonce = Constants.ONE_MOD_Q; var secret = Constants.TWO_MOD_Q; var keyPair = ElGamalKeyPair.FromSecret(secret); var publicKey = keyPair.PublicKey; var vote = 1UL; // Act var ciphertext = ElGamal.Encrypt(vote, nonce, publicKey); var plaintext = ciphertext.Decrypt(keyPair.SecretKey); // Assert Assert.That(plaintext == vote); }
void Encrypt_Button_Clicked(System.Object sender, System.EventArgs e) { var nonce = Constants.ONE_MOD_Q; // Don't use this secret key except for silly tests. var secretKey = Constants.TWO_MOD_Q; var keyPair = ElGamalKeyPair.FromSecret(secretKey); var publicKey = keyPair.PublicKey; ulong vote = 1; var ciphertext = Elgamal.Encrypt(vote, nonce, publicKey); // var plaintext = ciphertext.Decrypt(keyPair.SecretKey); ((Button)sender).Text = $"I encrypted a vote. Maybe even the one you asked for."; }
public void Test_Compact_Encrypt_Ballot_Simple_Succeeds() { var keypair = ElGamalKeyPair.FromSecret(Constants.TWO_MOD_Q); var description = new Manifest(jsonManifest); var manifest = new InternalManifest(description); var context = new CiphertextElectionContext(1UL, 1UL, keypair.PublicKey, Constants.TWO_MOD_Q, manifest.ManifestHash); var device = new EncryptionDevice(12345UL, 23456UL, 34567UL, "Location"); var mediator = new EncryptionMediator(manifest, context, device); var ballot = new PlaintextBallot(plaintext); // Act var compact = mediator.CompactEncrypt(ballot); // Assert Assert.That(compact.ObjectId == ballot.ObjectId); var msgpack = compact.ToMsgPack(); var fromMsgpack = new CompactCiphertextBallot(msgpack); Assert.That(compact.ObjectId == fromMsgpack.ObjectId); }