Exemplo n.º 1
0
        public void RoundTripTest()
        {
            var AliceKeys = new SigningKeyPair(new PrivateSecretKey(K_PRI_ALICE), new PublicKey(K_PUB_ALICE));

            var pen = new Signer(AliceKeys.Secret);

            var signature = pen.Sign(MESSAGE);

            Assert.IsTrue(signature.Verify(MESSAGE, AliceKeys.Public));
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public override SigningKeyPair GenerateKeyPair()
        {
            SigningKeyPair keyPair = new SigningKeyPair(new byte[32],new byte[64]);


            if(NativeLibsodium.crypto_sign_keypair(keyPair.publicKey,keyPair.secretKey) != 0)
                throw new Exception("Could not create new KeyPair");

            keyPair.algorythm = this;
            return keyPair;
        }
Exemplo n.º 3
0
        public void RoundTripTest_WrongMessage()
        {
            var AliceKeys  = new SigningKeyPair(new PrivateSecretKey(K_PRI_ALICE), new PublicKey(K_PUB_ALICE));
            var BobsPubKey = new PublicKey(K_PUB_BOB);

            var pen = new Signer(AliceKeys.Secret);

            var signature = pen.Sign(MESSAGE);

            Assert.IsFalse(signature.Verify(MESSAGE_CHANGED, BobsPubKey));
        }
Exemplo n.º 4
0
        public void NullParamterTest()
        {
            var keyPair = new SigningKeyPair(new PrivateSecretKey(K_PRI_ALICE), new PublicKey(K_PUB_ALICE));

            Assert.ThrowsException <ArgumentNullException>(() => new Signer(null));

            var pen = new Signer(keyPair.Secret);

            Assert.ThrowsException <ArgumentNullException>(() => pen.Sign(str: null));
            Assert.ThrowsException <ArgumentNullException>(() => pen.Sign(str: ""));
            Assert.ThrowsException <ArgumentNullException>(() => pen.Sign(data: null));
            Assert.ThrowsException <ArgumentNullException>(() => pen.Sign(data: new byte[0]));
        }
Exemplo n.º 5
0
        public void RoundTripTest_Tampered()
        {
            var AliceKeys = new SigningKeyPair(new PrivateSecretKey(K_PRI_ALICE), new PublicKey(K_PUB_ALICE));

            var pen = new Signer(AliceKeys.Secret);

            var signature = pen.Sign(MESSAGE);

            for (int i = 0; i < 5; i++)
            {
                signature.Bytes[i] = 0;
            }

            Assert.IsFalse(signature.Verify(MESSAGE, AliceKeys.Public));
        }