Exemplo n.º 1
0
        public void SimpleAuthTest()
        {
            var expected = Utilities.HexToBinary("8d5436accbe258a6b252c1140f38d7b8dc6196619945818b72512b6a8019d86dfeeb56f40c4d4b983d97dfeed37948527256c3567d6b253757fcfb32bef56f0b4164616d2043617564696c6c");
            var actual   = PublicKeyAuth.Sign(Encoding.UTF8.GetBytes("Adam Caudill"),
                                              Utilities.HexToBinary("89dff97c131434c11809c3341510ce63c85e851d3ba62e2f810016bbc67d35144ffda13c11d61d2b9568e54bec06ea59368e84874883087645e64e5e9653422e"));

            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 2
0
        /// <summary>
        ///  Sign the specified message with the private key.
        /// </summary>
        /// <param name='privateKey'>
        ///  The private key.
        /// </param>
        /// <param name='message'>
        ///  The message.
        /// </param>
        /// <returns>
        ///  The message that has been signed (encrypted) by the private key.
        /// </returns>
        public byte[] Sign(byte[] privateKey, byte[] message)
        {
            if (Keys == null)
            {
                Keys = PublicKeyAuth.GenerateKeyPair(privateKey);
            }

            return(PublicKeyAuth.Sign(message, Keys.PrivateKey));
        }
        public void VerifyTest()
        {
            var kp = PublicKeyAuth.GenerateKeyPair();

            byte[] message      = System.Text.Encoding.UTF8.GetBytes("Hello, World!");
            var    signature    = PublicKeyAuth.Sign(message, kp.Secret);
            var    verification = PublicKeyAuth.Verify(signature, kp.Public);

            Assert.AreEqual(message.ToString(), verification.ToString());
        }
Exemplo n.º 4
0
        public void SignAuthBadKey()
        {
            //Don`t copy bobSk for other tests (bad key)!
            //30 byte
            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
            };

            PublicKeyAuth.Sign(Encoding.UTF8.GetBytes("Adam Caudill"), bobSk);
        }
        public void SignAuthBadKey()
        {
            //Don`t copy bobSk for other tests (bad key)!
            //30 byte
            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");

            Assert.Throws <KeyOutOfRangeException>(
                () => PublicKeyAuth.Sign(message, bobSk));
        }
Exemplo n.º 6
0
        public void SignTest()
        {
            var kp = PublicKeyAuth.GenerateKeyPair();

            byte[] message   = System.Text.Encoding.UTF8.GetBytes("Hello, World!");
            var    signature = PublicKeyAuth.Sign(message, kp.Secret);

            // Test against a seed and expected output generated from libsodium
            var seed     = Convert.FromBase64String("zYZceFCtMRu4FAi/a47fN+21396uv/QcUMvi/u08zCw=");
            var expected = Convert.FromBase64String("BlWhHIrosG+Q7jq/lMgxkw79f7dM1x2u+IR6f5nPojaVdaXpUbSpzVSPT238CCDInCnQQ5ueMetEoaXYhET+CEhlbGxvLCBXb3JsZCE=");

            kp        = PublicKeyAuth.GenerateKeyPair(seed);
            signature = PublicKeyAuth.Sign(message, kp.Secret);
            Assert.AreEqual(expected.ToString(), signature.ToString());
        }
Exemplo n.º 7
0
 public static byte[] Sign(Tuple <byte[], byte[]> keyPair, string message)
 {
     return(PublicKeyAuth.Sign(Encoding.UTF8.GetBytes(message), keyPair.Item2));
 }
Exemplo n.º 8
0
        /*
         * public static byte[] CreatePrivateKey(string masterPassword) {
         *
         *      var hash = SHA256.Create().ComputeHash(value);
         * }
         * */

        public static byte[] CreateSignature(byte[] privateKey)
        {
            Debug.Assert(privateKey.Length == 32);
            return(PublicKeyAuth.Sign("hello", privateKey));
        }