public void Oakley2_Ctor() { using (var dh = new BCryptDiffieHellmanOakleyGroup2()) { Assert.IsNotNull(dh); } }
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 Oakley2_PublicKey() { var dh = new BCryptDiffieHellmanOakleyGroup2(); Assert.IsNotNull(dh); Assert.IsNotNull(dh.PublicKey); Assert.IsTrue(dh.PublicKey.KeyLength > 0); }
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 ReadOnlyMemory <byte> Modp2() { using (var alice = new BCryptDiffieHellmanOakleyGroup2()) using (var bob = new BCryptDiffieHellmanOakleyGroup2()) { alice.ImportPartnerKey(bob.PublicKey); bob.ImportPartnerKey(alice.PublicKey); return(alice.GenerateAgreement()); } }
public void Oakley2_KeyAgreement() { using (var alice = new BCryptDiffieHellmanOakleyGroup2()) using (var bob = new BCryptDiffieHellmanOakleyGroup2()) { Assert.IsFalse(bob.PublicKey.PublicComponent.Span.SequenceEqual(alice.PublicKey.PublicComponent.Span)); alice.ImportPartnerKey(GetRightPublicKey(alice.PublicKey, bob.PublicKey)); bob.ImportPartnerKey(GetRightPublicKey(bob.PublicKey, alice.PublicKey)); AssertKeysAgree(alice, bob); } }