public void Verification() { const string xml = @"<!-- root comment --> <root> <child>content</child> </root>"; var xDocument = XDocument.Parse(xml); var signedDocument = new SignedXDocument(xDocument); var withSignature = signedDocument.Sign(); Assert.IsTrue(SignedXDocument.Verify(withSignature)); }
public void VerificationAltered() { const string xml = @"<!-- root comment --> <root> <child>content</child> </root>"; var xDocument = XDocument.Parse(xml); var signedDocument = new SignedXDocument(xDocument); var withSignature = signedDocument.Sign(); var altered = new XDocument(withSignature); altered.Root?.Add(new XElement(@"dummy")); Assert.IsFalse(SignedXDocument.Verify(altered)); }
public void VerificationWithProperties() { const string xml = @"<!-- root comment --> <root> <child>content</child> </root>"; var xDocument = XDocument.Parse(xml); var signedDocument = new SignedXDocument(xDocument) { SignatureProperties = new List <XElement> { new XElement(@"SomeProperty", @"SomeValue") } }; var withSignature = signedDocument.Sign(); Assert.IsTrue(SignedXDocument.Verify(withSignature)); }
public void VerificationWithPropertiesAltered() { const string xml = @"<!-- root comment --> <root> <child>content</child> </root>"; var xDocument = XDocument.Parse(xml); var signedDocument = new SignedXDocument(xDocument) { SignatureProperties = new List <XElement> { new XElement(@"SomeProperty", @"SomeValue", new [] { new XAttribute(@"Id", @"property") }) } }; var withSignature = signedDocument.Sign(); var altered = new XDocument(withSignature); var propertyNode = altered.XPathSelectElement(@"//*[@Id='property']"); propertyNode?.SetValue(@"SomeAlteredValue"); Assert.IsFalse(SignedXDocument.Verify(altered)); }