private void CheckEncryption(Envelope envelope, Attachment attachment) { var xml = ObjectToXml.Serialize(envelope); var certificate = Certificates.CreateSelfSigned(); var expected = Copy(attachment.Stream); var encrypter = new EbmsEncrypter { Xml = xml, Attachments = new [] { attachment }, PublicKeyInAsn1Format = certificate.GetPublicKey() }; encrypter.Encrypt(); var decrypter = new EbmsDecrypter { Xml = xml, Attachments = new [] { attachment }, Certificate = certificate }; decrypter.Decrypt(); var actual = Copy(attachment.Stream); Assert.IsTrue(expected.SequenceEqual(actual)); }
public void SignAndVerify() { var xml = new XmlDocument(); xml.LoadXml( @"<sbdh:StandardBusinessDocument xmlns:sbdh=""http://eessi.dgempl.ec.europa.eu/namespaces/sbdh""> <sbdh:StandardBusinessDocumentHeader> </sbdh:StandardBusinessDocumentHeader> <sed:StructuredElectronicDocument xmlns:sed=""http://ec.europa.eu/eessi/ns/sed""> </sed:StructuredElectronicDocument> </sbdh:StandardBusinessDocument>"); var xadesSigner = new XadesSigner { Certificate = Certificates.CreateSelfSigned(), Xml = xml }; xadesSigner.Sign(); var xadesVerifier = new XadesVerifier { Xml = xml }; var isSignatureCorrect = xadesVerifier.Verify(); Assert.IsTrue(isSignatureCorrect); }
private void CheckSigning(Envelope envelope, params Attachment[] attachments) { var xml = ObjectToXml.Serialize(envelope); var ebmsSigner = new EbmsSigner { Xml = xml, Certificate = Certificates.CreateSelfSigned(), Uris = new [] { envelope.Header.Messaging.Id, envelope.Body.Id }, Attachments = attachments }; ebmsSigner.Sign(); var ebmsVerifier = new EbmsVerifier { Xml = xml, Attachments = attachments }; ebmsVerifier.Verify(); }