Skip to content

Commit 0fe8d41

Browse files
Merge pull request #608 from SyncfusionExamples/DigitalSign
162875-Added README.md files for digital signature samples for Demo list
2 parents c920e6d + 992353a commit 0fe8d41

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

  • Digital-Signature
    • Add-digital-signature-invisible/.NET/Add-digital-signature-invisible
    • Validate-digital-signature/.NET/Validate-digital-signature
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Add a digital signature in a Word document using C#
2+
3+
The [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (DocIO) empowers you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **add an invisible digital signature to a Word document** using C#.
4+
5+
## Steps to add an invisible digital signature to a Word document programmatically
6+
7+
Step 1: Create a new .NET Core console application project.
8+
9+
Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).
10+
11+
Step 3: Include the following namespaces in the Program.cs file.
12+
13+
```csharp
14+
using Syncfusion.DocIO;
15+
using Syncfusion.DocIO.DLS;
16+
using Syncfusion.Office;
17+
```
18+
19+
Step 4: Add the following code snippet in Program.cs file to add an invisible digital signature to a Word document.
20+
21+
```csharp
22+
//Opens an existing Word document.
23+
WordDocument document = new WordDocument(Path.GetFullPath(@"Data\Template.docx"));
24+
//Loads the signing certificate from disk.
25+
OfficeDigitalSignatureCertificate certificate = new OfficeDigitalSignatureCertificate(Path.GetFullPath(@"Data\certificate.pfx"), "password123");
26+
//Configures signature settings.
27+
SignatureSettings settings = new SignatureSettings();
28+
settings.Comments = "Approved";
29+
settings.SignTime = DateTime.Now;
30+
//Sets the application version used to create the signature.
31+
settings.ApplicationVersion = "16.0";
32+
//Sets the Office version recorded with the signature.
33+
settings.OfficeVersion = "16.0";
34+
//Sets the Windows version recorded with the signature.
35+
settings.WindowsVersion = "10.0";
36+
//Sets the horizontal resolution recorded with the signature.
37+
settings.HorizontalResolution = 1920;
38+
//Sets the vertical resolution recorded with the signature.
39+
settings.VerticalResolution = 1080;
40+
//Sets the color depth recorded with the signature.
41+
settings.ColorDepth = 32;
42+
//Sets the cryptographic provider identifier.
43+
settings.ProviderId = new Guid("00000000-0000-0000-0000-000000000000");
44+
//Adds an invisible digital signature to the document using the certificate and settings.
45+
document.AddDigitalSignature(certificate, settings);
46+
//Saves the Word document to file.
47+
document.Save(Path.GetFullPath(@"Output\Result.docx"), FormatType.Docx);
48+
//Closes the document
49+
document.Close();
50+
```
51+
52+
More information about add a digital signature in a Word document can be refer in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-digital-signature) section.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Validate a digital signature in a Word document using C#
2+
3+
The [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (DocIO) empowers you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **validate digital signatures in a Word document** using C#.
4+
5+
## Steps to validate digital signatures in a Word document programmatically
6+
7+
Step 1: Create a new .NET Core console application project.
8+
9+
Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).
10+
11+
Step 3: Include the following namespaces in the Program.cs file.
12+
13+
```csharp
14+
using Syncfusion.DocIO;
15+
using Syncfusion.DocIO.DLS;
16+
using Syncfusion.Office;
17+
```
18+
19+
Step 4: Add the following code snippet in Program.cs file to validate digital signatures in a Word document.
20+
21+
```csharp
22+
//Opens the signed Word document.
23+
WordDocument document = new WordDocument(Path.GetFullPath(@"Data\SignedDocument.docx"));
24+
//Gets the digital signature collection in the document.
25+
OfficeDigitalSignatureCollection signatures = document.DigitalSignatures;
26+
//Checks whether every digital signature in the collection is valid.
27+
bool allValid = signatures.IsValid;
28+
Console.WriteLine("All signatures are valid : " + allValid);
29+
//Iterates through each signature and checks whether it is valid.
30+
foreach (OfficeDigitalSignature signature in signatures)
31+
{
32+
//Checks whether the signature is valid.
33+
bool isValid = signature.IsValid;
34+
Console.WriteLine("Signature is valid : " + isValid);
35+
}
36+
//Closes the document
37+
document.Close();
38+
```
39+
40+
More information about validate a digital signature in a Word document can be refer in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-digital-signature) section.

0 commit comments

Comments
 (0)