Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active May 31, 2019 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/c29c9a04961589b3ee5f34a9ee0e5afb to your computer and use it in GitHub Desktop.
Save GroupDocsGists/c29c9a04961589b3ee5f34a9ee0e5afb to your computer and use it in GitHub Desktop.
//For complete examples and data files, please go to https://github.com/groupdocs-signature/GroupDocs.Signature-for-.NET
public class DocumentSignature
{
// specify SkipSerialization attribute to skip this field on serialization
[SkipSerialization]
public string Version { get; set; }
// specify SkipSerialization attribute to skip this field on serialization
[SkipSerialization]
public bool IsProcessed { get; set; }
[Format("SignatureID")]
public string ID { get; set; }
[Format("Author")]
public string Author { get; set; }
[Format("SignatureDate","yyyy-MM-dd")]
public DateTime Signed { get; set; }
[Format("Factor", "N2")]
public decimal DataFactor { get; set; }
}
//For complete examples and data files, please go to https://github.com/groupdocs-signature/GroupDocs.Signature-for-.NET
// Setup key and passphrase
string key = "1234567890";
string salt = "1234567890";
// Create data encryption
IDataEncryption encryption = new SymmetricEncryption(SymmetricAlgorithmType.Rijndael, key, salt);
// Setup Signature configuration
SignatureConfig signConfig = new SignatureConfig
{
StoragePath = @"c:\Aspose\Test\Storage",
OutputPath = @"c:\Aspose\Test\Output"
};
// Instantiate the signature handler
SignatureHandler handler = new SignatureHandler(signConfig);
// Setup options with text of signature
PdfMetadataSignOptions signOptions = new PdfMetadataSignOptions();
// Create custom object
DocumentSignature signature = new DocumentSignature()
{
ID = Guid.NewGuid().ToString(),
Author = Environment.UserName,
Signed = DateTime.Now,
DataFactor = 11.22M
};
// Specify different Metadata Signatures and add them to signature collection
PdfMetadataSignature mdDocument = new PdfMetadataSignature("DocumentSignature", signature);
// Set encryption
mdDocument.DataEncryption = encryption;
signOptions.MetadataSignatures.Add(mdDocument);
// Sign document
string signedPath = handler.Sign<string>("test.pdf", signOptions,
new SaveOptions { OutputType = OutputType.String, OutputFileName = "SignedMedataDataEncrypted.pdf" });
Console.WriteLine("Signed file path is: " + signedPath);
//For complete examples and data files, please go to https://github.com/groupdocs-signature/GroupDocs.Signature-for-.NET
// Setup Signature configuration
SignatureConfig signConfig = new SignatureConfig
{
StoragePath = @"c:\Aspose\Storage",
OutputPath = @"c:\Aspose\Output"
};
// Instantiating the signature handler
SignatureHandler handler = new SignatureHandler(signConfig);
// Setup options with text of signature
PdfMetadataSignOptions signOptions = new PdfMetadataSignOptions();
// Create custom object
DocumentSignature signature = new DocumentSignature()
{
ID = Guid.NewGuid().ToString(),
Author = Environment.UserName,
Signed = DateTime.Now,
DataFactor = 11.22M
};
// Specify different Metadata Signatures and add them to signature collection
PdfMetadataSignature mdDocument = new PdfMetadataSignature("DocumentSignature", signature);
signOptions.MetadataSignatures.Add(mdDocument);
// Sign document
string signedPath = handler.Sign<string>("test.pdf", signOptions,
new SaveOptions { OutputType = OutputType.String, OutputFileName = "SignedMedataDataEncrypted.pdf" });
Console.WriteLine("Signed file path is: " + signedPath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment