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));
        }
Ejemplo n.º 2
0
 public void PublicKeyBoxCreateDetachedWithBadNonce()
 {
     PublicKeyBox.CreateDetached(
         Encoding.UTF8.GetBytes("Adam Caudill"),
         Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVX"),
         Utilities.HexToBinary("2a5c92fac62514f793c0bfd374f629a138c5702793a32c61dadc593728a15975"),
         Utilities.HexToBinary("83638e30326e2f55509286ac86afeb5bfd0732a3d11747bd50eb96bb9ec85645"));
 }
Ejemplo n.º 3
0
        public void PublicKeyBoxCreateDetachedWithBadPublicKey()
        {
            var bobPk = new byte[] {
                0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b,
                0x79, 0xe1, 0x7f, 0x8b, 0x83, 0x80, 0x0e, 0xe6,
                0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18, 0xb6, 0xfd,
                0x1c, 0x2f, 0x8b, 0x27, 0xff, 0x88
            };

            PublicKeyBox.CreateDetached(
                Encoding.UTF8.GetBytes("Adam Caudill"),
                Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWX"),
                Utilities.HexToBinary("2a5c92fac62514f793c0bfd374f629a138c5702793a32c61dadc593728a15975"), bobPk);
        }
Ejemplo n.º 4
0
        public void PublicKeyBoxCreateDetachedWithBadPrivateKey()
        {
            var bobSk = new byte[] {
                0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b,
                0x79, 0xe1, 0x7f, 0x8b, 0x83, 0x80, 0x0e, 0xe6,
                0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18, 0xb6, 0xfd,
                0x1c, 0x2f, 0x8b, 0x27, 0xff, 0x88
            };

            PublicKeyBox.CreateDetached(
                Encoding.UTF8.GetBytes("Adam Caudill"),
                Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWX"), bobSk,
                Utilities.HexToBinary("83638e30326e2f55509286ac86afeb5bfd0732a3d11747bd50eb96bb9ec85645"));
        }
        public void PublicKeyBoxCreateDetachedWithBadPublicKey()
        {
            var bobPk = new byte[] {
                0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b,
                0x79, 0xe1, 0x7f, 0x8b, 0x83, 0x80, 0x0e, 0xe6,
                0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18, 0xb6, 0xfd,
                0x1c, 0x2f, 0x8b, 0x27, 0xff, 0x88
            };
            var message = Encoding.UTF8.GetBytes("Adam Caudill");
            var nonce   = Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWX");
            var aliceSk = Utilities.HexToBinary("2a5c92fac62514f793c0bfd374f629a138c5702793a32c61dadc593728a15975");

            Assert.Throws <KeyOutOfRangeException>(
                () => PublicKeyBox.CreateDetached(message, nonce, aliceSk, bobPk));
        }
        public void PublicKeyBoxCreateDetachedWithBadPrivateKey()
        {
            var bobSk = new byte[] {
                0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b,
                0x79, 0xe1, 0x7f, 0x8b, 0x83, 0x80, 0x0e, 0xe6,
                0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18, 0xb6, 0xfd,
                0x1c, 0x2f, 0x8b, 0x27, 0xff, 0x88
            };
            var message = Encoding.UTF8.GetBytes("Adam Caudill");
            var nonce   = Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWX");
            var alicePk = Utilities.HexToBinary("83638e30326e2f55509286ac86afeb5bfd0732a3d11747bd50eb96bb9ec85645");

            Assert.Throws <KeyOutOfRangeException>(
                () => PublicKeyBox.CreateDetached(message, nonce, bobSk, alicePk));
        }
        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"));
            });
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }