/// <summary> /// Return a List of Signer in the package /// </summary> /// <returns> /// Package Path (string), Signer Name (string), Signer URI (string), Signer Issuer (string) /// </returns> public Signers GetDigitalSigners() { Signers sigs = new Signers(); sigs.Path = signers.Path; List <X509Certificate2> certificateList = new List <X509Certificate2>(); List <XmlSignaturePart> xmlSignaturePartList = this.GetDigitalSignatures(); if (DocumentType.Equals(Types.XpsDocument)) { //To collect the information of the signature we used XPS like a System.IO.Packaging xpsDocument.Close(); package = Package.Open(signers.Path, FileMode.Open, FileAccess.Read); PackageDigitalSignatureManager _signatures = null; _signatures = new PackageDigitalSignatureManager(package); _signatures.CertificateOption = CertificateEmbeddingOption.InSignaturePart; // Add the signers in the list foreach (PackageDigitalSignature signature in _signatures.Signatures) { string name = signature.Signer.Subject.Replace("CN=", ""); string uri = signature.SignaturePart.Uri.ToString(); string date = signature.SigningTime.ToString(); string issuer = signature.Signer.Issuer.Replace("CN=", ""); string serial = signature.Signer.GetSerialNumberString(); X509Certificate2 signatureCertificate = (X509Certificate2)signature.Signer; sigs.Add(name, uri, issuer, date, serial, signatureCertificate); } package.Close(); xpsDocument = new XpsDocument(signers.Path, FileAccess.ReadWrite); return(sigs); } else { PackageDigitalSignatureManager _signatures = null; _signatures = new PackageDigitalSignatureManager(package); _signatures.CertificateOption = CertificateEmbeddingOption.InSignaturePart; // Add the signers in the list foreach (PackageDigitalSignature signature in _signatures.Signatures) { string name = signature.Signer.Subject.Replace("CN=", ""); string uri = signature.SignaturePart.Uri.ToString(); string date = signature.SigningTime.ToString(); string issuer = signature.Signer.Issuer.Replace("CN=", ""); string serial = signature.Signer.GetSerialNumberString(); X509Certificate2 signatureCertificate = (X509Certificate2)signature.Signer; sigs.Add(name, uri, issuer, date, serial, signatureCertificate); } return(sigs); } }
private void SetDigitalSignatureOriginPartbyDocumentType() { if (DocumentType == Types.WordProcessingML) { digSigOrigin = WordprocessingDocument.Open(package).DigitalSignatureOriginPart; } if (DocumentType == Types.SpreadSheetML) { digSigOrigin = SpreadsheetDocument.Open(package).DigitalSignatureOriginPart; } if (DocumentType == Types.PresentationML) { digSigOrigin = PresentationDocument.Open(package).DigitalSignatureOriginPart; } signers = GetDigitalSigners(); }
/// <summary> /// Return a List of Signer in the package /// </summary> /// <returns> /// Package Path (string), Signer Name (string), Signer URI (string), Signer Issuer (string) /// </returns> public Signers GetDigitalSigners() { Signers sigs = new Signers(); sigs.Path = signers.Path; List <X509Certificate2> certificateList = new List <X509Certificate2>(); List <XmlSignaturePart> xmlSignaturePartList = this.GetDigitalSignatures(); if (DocumentType.Equals(Types.XpsDocument)) { //To collect the information of the signature we used XPS like a System.IO.Packaging xpsDocument.Close(); package = Package.Open(signers.Path, FileMode.Open, FileAccess.Read); PackageDigitalSignatureManager _signatures = null; _signatures = new PackageDigitalSignatureManager(package); _signatures.CertificateOption = CertificateEmbeddingOption.InSignaturePart; // Add the signers in the list foreach (PackageDigitalSignature signature in _signatures.Signatures) { string name = signature.Signer.Subject.Replace("CN=", ""); string uri = signature.SignaturePart.Uri.ToString(); string date = signature.SigningTime.ToString(); string issuer = signature.Signer.Issuer.Replace("CN=", ""); string serial = signature.Signer.GetSerialNumberString(); X509Certificate2 signatureCertificate = (X509Certificate2)signature.Signer; sigs.Add(name, uri, issuer, date, serial, signatureCertificate); } package.Close(); xpsDocument = new XpsDocument(signers.Path, FileAccess.ReadWrite); return(sigs); } else if (DocumentType.Equals(Types.PdfDocument)) { if (this.pdfSignatureList == null) { try { this.pdfSignatureList = CertificadoDigital.Validate.validateFile(pdfDocumentPath); } catch (CertificadoDigital.NoSignatureFoundException nsfe) { } } if (this.pdfSignatureList != null) { foreach (CertificadoDigital.Signature sig in this.pdfSignatureList) { string name = sig.OfficeTemplateSubject().Replace("CN=", ""); string uri = null; string date = sig.DateTime.ToString(); string issuer = sig.OfficeTemplateIssuer().Replace("CN=", ""); string serial = sig.Certificates[0].Serial; sigs.Add(name, uri, issuer, date, serial, sig.X509Certificate); } } return(sigs); } else { PackageDigitalSignatureManager _signatures = null; _signatures = new PackageDigitalSignatureManager(package); _signatures.CertificateOption = CertificateEmbeddingOption.InSignaturePart; // Add the signers in the list foreach (PackageDigitalSignature signature in _signatures.Signatures) { string name = signature.Signer.Subject.Replace("CN=", ""); string uri = signature.SignaturePart.Uri.ToString(); string date = signature.SigningTime.ToString(); string issuer = signature.Signer.Issuer.Replace("CN=", ""); string serial = signature.Signer.GetSerialNumberString(); X509Certificate2 signatureCertificate = (X509Certificate2)signature.Signer; sigs.Add(name, uri, issuer, date, serial, signatureCertificate); } return(sigs); } }