예제 #1
0
        public void TestSignAndVerify(String subDir, string nestDir)
        {
            using (var signer = new VanillaSigner(Util.TestDataPath(TEST_DATA, subDir, nestDir)))
                using (var verifier = new VanillaVerifier(Util.TestDataPath(TEST_DATA, subDir, nestDir)))
                {
                    var sig = signer.Sign(input);

                    Expect(signer.Verify(input, sig), Is.True);
                    Expect(signer.Verify("Wrong string", sig), Is.False);

                    Expect(verifier.Verify(input, sig), Is.True);
                    Expect(verifier.Verify("Wrong string", sig), Is.False);
                }
        }
예제 #2
0
        public void TestSignAndVerify(String subDir, string nestDir)
        {
            using (var signer = new VanillaSigner(Util.TestDataPath(TEST_DATA, subDir, nestDir)))
            using (var verifier = new VanillaVerifier(Util.TestDataPath(TEST_DATA, subDir, nestDir)))
            {
                var sig = signer.Sign(input);

                Expect(signer.Verify(input, sig), Is.True);
                Expect(signer.Verify("Wrong string", sig), Is.False);

                Expect(verifier.Verify(input, sig), Is.True);
                Expect(verifier.Verify("Wrong string", sig), Is.False);
            }
        }
예제 #3
0
        public override byte[] Sign(byte[] input)
        {
            if (!_signing)
            {
                throw new InvalidOperationException();
            }

            JwtAlg chosenAlg = Algorithm;

            if (!Jwt.IsValidAlg(chosenAlg, _keySet.GetPrimaryKey()))
            {
                throw new InvalidKeyTypeException("Key doesn't match chosen algorithm");
            }

            using (var vanillaSigner = new VanillaSigner(_keySet))
            {
                var sig = vanillaSigner.Sign(input);
                return(sig);
            }
        }
예제 #4
0
        public void TestVanillaSignAndVerify(String subDir)
        {
            using (var signer = new VanillaSigner(Util.TestDataPath(TEST_DATA, subDir)))
            {
                var streamInput = new MemoryStream();
                streamInput.Write(new byte[ExtraDataLength], 0, ExtraDataLength);
                using (Utility.ResetStreamWhenFinished(streamInput))
                {
                    InputStream.CopyTo(streamInput);
                    streamInput.Write(new byte[ExtraDataLength], 0, ExtraDataLength);
                }

                Expect(streamInput.Position, Is.EqualTo(ExtraDataLength));
                byte[] sig;
                // Create a signature that will be valid for a long time
                using (Utility.ResetStreamWhenFinished(streamInput))
                    sig = signer.Sign(streamInput, InputStream.Length);
                Expect(streamInput.Position, Is.EqualTo(ExtraDataLength));
                Expect(signer.Verify(streamInput, sig, InputStream.Length), Is.True);
                Expect(streamInput.Position, Is.EqualTo(InputStream.Length + ExtraDataLength));
            }
        }