Digital Signatures

Digital Signatures

Aspose.Words FOSS for .NET can inspect and verify digital signatures that are already attached to a .docx document through the Aspose.Words.DigitalSignatures namespace. This edition covers signature verification — reading signature metadata, checking validity, and examining the signing certificate. It does not include the ability to create new signatures on a document.


Reading Signatures from a Document

Every Document exposes a DigitalSignatures property returning a DigitalSignatureCollection — a read-only, enumerable collection of DigitalSignature objects already present in the loaded file. DigitalSignatureUtil.LoadSignatures(fileName) (and the LoadSignatures(stream) overload) reads signatures directly from a file or stream without loading the full document into a Document object, which is useful when you only need to check signature status. The collection’s IsValid property reports whether every signature it contains is valid, and Count reports how many signatures were found.


Inspecting an Individual Signature

Each DigitalSignature exposes IsValid (whether the signature is cryptographically valid), SignatureType (a DigitalSignatureType value — CryptoApi, XmlDsig, or Unknown), SignTime, Comments, SubjectName, IssuerName, and the raw SignatureValue bytes. The CertificateHolder property returns a CertificateHolder object wrapping the signing certificate; its Certificate property exposes the underlying X509Certificate2 so you can inspect standard certificate fields (issuer, subject, validity period) with .NET’s own certificate APIs.


What’s Not Supported in This Edition

The API surface still declares signing-related members — DigitalSignatureUtil.Sign(), SignOptions, and XmlDsigLevel — for structural compatibility with the commercial Aspose.Words for .NET object model, but creating a new digital signature on a document is not functional in this FOSS edition. Use this edition to verify signatures that already exist in a document; a signing workflow requires Aspose.Words for .NET.


Tips and Best Practices

  • Prefer DigitalSignatureUtil.LoadSignatures() over opening the full Document when you only need to check whether a file is signed — it avoids the cost of parsing the entire document body.
  • Check DigitalSignatureCollection.IsValid first for a quick pass/fail before iterating individual DigitalSignature.IsValid values.
  • SignatureType tells you which signing mechanism produced the signature (CryptoApi vs. XmlDsig); this affects which certificate fields are meaningful.
  • Treat IsValid == false as a hard failure condition in any automated document-intake pipeline — do not surface signature metadata from an invalid signature as trustworthy.

Common Issues

IssueCauseFix
DigitalSignatures.Count is 0 on a signed .docxFile was re-saved by a tool that stripped the signature partVerify against the original signed file, not a re-saved copy
Signature reports IsValid = falseDocument content changed after signing, or the certificate is untrusted/expiredTreat as invalid; do not attempt to “repair” the signature
Attempting to sign a document has no effectSigning is not implemented in this FOSS editionUse Aspose.Words for .NET (commercial) for signing workflows
CertificateHolder.Certificate throws when inspectedUnderlying certificate data is malformed or the signature part is corruptConfirm the source file is a genuine, unmodified signed document

FAQ

Can Aspose.Words FOSS for .NET sign a document?

No. This edition can verify existing digital signatures but cannot create new ones. The DigitalSignatureUtil.Sign() method and SignOptions class exist in the API surface for structural compatibility, but signing is not functional here.

How do I check if a document is signed without loading it fully?

Call DigitalSignatureUtil.LoadSignatures(fileName), which returns a DigitalSignatureCollection directly from the file.

What does DigitalSignatureCollection.IsValid mean?

It is true only when every signature in the collection is individually valid — a quick way to check overall document signature integrity before inspecting each DigitalSignature.

Where do I get the certificate details for a signature?

Through DigitalSignature.CertificateHolder.Certificate, which returns a standard .NET X509Certificate2.


API Reference Summary

Class / MethodDescription
Document.DigitalSignaturesSignatures already attached to a loaded document
DigitalSignatureUtil.LoadSignatures()Read signatures from a file or stream without loading the full document
DigitalSignatureCollectionRead-only collection of DigitalSignature objects; IsValid, Count
DigitalSignatureA single signature: IsValid, SignTime, SubjectName, IssuerName, CertificateHolder
DigitalSignatureTypeEnum: CryptoApi, XmlDsig, Unknown
CertificateHolderWraps the signing X509Certificate2