protected override IKeyAgreement StartKeyAgreement() { IKeyAgreement agreement = null; switch (random.Next(4)) { case 0: agreement = new BCryptDiffieHellmanOakleyGroup14(); break; case 1: agreement = new BCryptDiffieHellmanOakleyGroup2(); break; case 2: agreement = new ManagedDiffieHellmanOakley14(); break; case 3: agreement = new ManagedDiffieHellmanOakley2(); break; } W($"DH Type: {agreement.GetType()}"); if (agreement == null) { throw new ArgumentException("How did it get here?"); } return(agreement); }
public void ManagedExportAgreeswithNativeImportGroup2() { DiffieHellmanKey managedExport; using (var alice = new ManagedDiffieHellmanOakley2()) using (var bob = new ManagedDiffieHellmanOakley2()) { managedExport = alice.PrivateKey as DiffieHellmanKey; alice.ImportPartnerKey(bob.PublicKey); bob.ImportPartnerKey(alice.PublicKey); AssertKeysAgree(alice, bob); } managedExport.Generator = Pad(managedExport.Generator, managedExport.KeyLength); using (var alice = BCryptDiffieHellman.Import(managedExport)) using (var bob = new BCryptDiffieHellmanOakleyGroup2()) { alice.ImportPartnerKey(bob.PublicKey); bob.ImportPartnerKey(alice.PublicKey); AssertKeysAgree(alice, bob); } }
public void ManagedAgreesWithNativeGroup2() { using (var alice = new BCryptDiffieHellmanOakleyGroup2()) using (var bob = new ManagedDiffieHellmanOakley2()) { alice.ImportPartnerKey(bob.PublicKey); bob.ImportPartnerKey(alice.PublicKey); AssertKeysAgree(alice, bob); } }
public void ManagedExportMatchesNativeImport() { using (var alice = new ManagedDiffieHellmanOakley2()) { var managedExportPrivate = alice.PrivateKey as DiffieHellmanKey; var managedExportPublic = alice.PublicKey as DiffieHellmanKey; managedExportPrivate.Generator = Pad(managedExportPrivate.Generator, managedExportPrivate.KeyLength); managedExportPublic.Generator = Pad(managedExportPublic.Generator, managedExportPublic.KeyLength); using (var bob = BCryptDiffieHellman.Import(managedExportPrivate)) { AssertKeysMatch(alice.PrivateKey, bob.PrivateKey); AssertKeysMatch(alice.PublicKey, bob.PublicKey); alice.ImportPartnerKey(bob.PublicKey); bob.ImportPartnerKey(alice.PublicKey); AssertKeysAgree(alice, bob); } } }