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); } }
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); } }
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)); } }