public void DetachedBoxTest() { var alice = PublicKeyBox.GenerateKeyPair(); var bob = PublicKeyBox.GenerateKeyPair(); var nonce = PublicKeyBox.GenerateNonce(); String message = "Hello, World!"; byte[] byteMessage = System.Text.Encoding.UTF8.GetBytes(message); var e1 = PublicKeyBox.CreateDetached(message, nonce, bob.Secret, alice.Public); var e2 = PublicKeyBox.CreateDetached(message, nonce, bob.Secret, alice.Public); Assert.AreEqual(Convert.ToBase64String(e1.Cipher), Convert.ToBase64String(e2.Cipher)); Assert.AreEqual(Convert.ToBase64String(e1.Mac), Convert.ToBase64String(e2.Mac)); var d1 = PublicKeyBox.OpenDetached(e1, nonce, alice.Secret, bob.Public); var d2 = PublicKeyBox.OpenDetached(e2, nonce, alice.Secret, bob.Public); Assert.AreEqual(message, System.Text.Encoding.UTF8.GetString(d1)); Assert.AreEqual(message, System.Text.Encoding.UTF8.GetString(d2)); d1 = PublicKeyBox.OpenDetached(e1.Cipher, e1.Mac, nonce, alice.Secret, bob.Public); d2 = PublicKeyBox.OpenDetached(e2.Cipher, e2.Mac, nonce, alice.Secret, bob.Public); Assert.AreEqual(message, System.Text.Encoding.UTF8.GetString(d1)); Assert.AreEqual(message, System.Text.Encoding.UTF8.GetString(d2)); }
public void PublicKeyBoxOpenDetachedBadMac() { var actual = PublicKeyBox.CreateDetached( Encoding.UTF8.GetBytes("Adam Caudill"), Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWX"), Utilities.HexToBinary("2a5c92fac62514f793c0bfd374f629a138c5702793a32c61dadc593728a15975"), Utilities.HexToBinary("83638e30326e2f55509286ac86afeb5bfd0732a3d11747bd50eb96bb9ec85645")); Assert.Throws <MacOutOfRangeException>(() => { PublicKeyBox.OpenDetached(actual.CipherText, null, Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWX"), Utilities.HexToBinary("2a5c92fac62514f793c0bfd374f629a138c5702793a32c61dadc593728a15975"), Utilities.HexToBinary("83638e30326e2f55509286ac86afeb5bfd0732a3d11747bd50eb96bb9ec85645")); }); }
public void DetachedBox() { var expected = Utilities.HexToBinary("4164616d2043617564696c6c"); var actual = PublicKeyBox.CreateDetached( Encoding.UTF8.GetBytes("Adam Caudill"), Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWX"), Utilities.HexToBinary("2a5c92fac62514f793c0bfd374f629a138c5702793a32c61dadc593728a15975"), Utilities.HexToBinary("83638e30326e2f55509286ac86afeb5bfd0732a3d11747bd50eb96bb9ec85645")); var clear = PublicKeyBox.OpenDetached(actual.CipherText, actual.Mac, Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWX"), Utilities.HexToBinary("2a5c92fac62514f793c0bfd374f629a138c5702793a32c61dadc593728a15975"), Utilities.HexToBinary("83638e30326e2f55509286ac86afeb5bfd0732a3d11747bd50eb96bb9ec85645")); Assert.AreEqual(clear, expected); }
public void PublicKeyBoxOpenDetachedBadMac() { var actual = PublicKeyBox.CreateDetached( Encoding.UTF8.GetBytes("Adam Caudill"), Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWX"), Utilities.HexToBinary("2a5c92fac62514f793c0bfd374f629a138c5702793a32c61dadc593728a15975"), Utilities.HexToBinary("83638e30326e2f55509286ac86afeb5bfd0732a3d11747bd50eb96bb9ec85645")); var clear = PublicKeyBox.OpenDetached(actual.CipherText, null, Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWX"), Utilities.HexToBinary("2a5c92fac62514f793c0bfd374f629a138c5702793a32c61dadc593728a15975"), Utilities.HexToBinary("83638e30326e2f55509286ac86afeb5bfd0732a3d11747bd50eb96bb9ec85645")); //we shouldn't get here Assert.IsNull(clear); }