public static void ReadXmlSigned(this FatturaBase fattura, Stream stream, bool validateSignature = true) { CmsSignedData signedFile = new CmsSignedData(stream); if (validateSignature) { IX509Store certStore = signedFile.GetCertificates("Collection"); ICollection certs = certStore.GetMatches(new X509CertStoreSelector()); SignerInformationStore signerStore = signedFile.GetSignerInfos(); ICollection signers = signerStore.GetSigners(); foreach (object tempCertification in certs) { Org.BouncyCastle.X509.X509Certificate certification = tempCertification as Org.BouncyCastle.X509.X509Certificate; foreach (object tempSigner in signers) { SignerInformation signer = tempSigner as SignerInformation; if (!signer.Verify(certification.GetPublicKey())) { throw new FatturaElettronicaSignatureException(Resources.ErrorMessages.SignatureException); } } } } using (var memoryStream = new MemoryStream()) { signedFile.SignedContent.Write(memoryStream); fattura.ReadXml(memoryStream); } }
public static void ReadXmlSigned(this FatturaBase fattura, Stream stream, bool validateSignature = true) { using (var parsed = ParseSignature(stream, validateSignature)) { fattura.ReadXml(parsed); } }
public static void ReadXml(this FatturaBase fattura, string filePath) { using (var r = XmlReader.Create(filePath, new XmlReaderSettings { IgnoreWhitespace = true, IgnoreComments = true, IgnoreProcessingInstructions = true })) { fattura.ReadXml(r); } }
public static void ReadXml(this FatturaBase fattura, Stream stream) { stream.Position = 0; using (var r = XmlReader.Create(stream, new XmlReaderSettings { IgnoreWhitespace = true, IgnoreComments = true, IgnoreProcessingInstructions = true })) { fattura.ReadXml(r); } }