Sign documents with encrypted metadata text
Leave feedback
GroupDocs.Signature provides ability to secure Metadata signatures with standard or custom encryption. Standard encryption is implemented over class SymmetricEncryption class. Creation of this object expects 3 arguments like encryption algorithm enumeration SymmetricAlgorithmType with one of following values (DES, TripleDES, RC2, Rijndael), string value key and string value salt.
Here are the steps to secure Metadata string values with standard encryption with GroupDocs.Signature:
Create new instance of Signature class and pass source document path or stream as a constructor parameter.
Compose object of SymmetricEncryption class with required algorithm and secure pair key/salt
Alternative way to encrypt only selected Metadata signatures is to setup property MetadataSignature.DataEncryption to each signature that requires to be secured.
This example shows how to sign document with encrypted Metadata signatures over .
using(Signaturesignature=newSignature("sample.docx")){// setup key and passphrasestringkey="1234567890";stringsalt="1234567890";// create data encryptionIDataEncryptionencryption=newSymmetricEncryption(SymmetricAlgorithmType.Rijndael,key,salt);// setup options with text of signatureMetadataSignOptionsoptions=newMetadataSignOptions(){};// setup signature metadata - this text will not be encryptedWordProcessingMetadataSignaturemdAuthor=newWordProcessingMetadataSignature("Author","Mr.Scherlock Holmes");// setup data of document idWordProcessingMetadataSignaturemdDocId=newWordProcessingMetadataSignature("DocumentId",Guid.NewGuid().ToString());// set encryption for separate metadata signatures for this optionsmdDocId.DataEncryption=encryption// add signatures to optionsoptions.Signatures.Add(mdAuthor);options.Signatures.Add(mdDocId);// sign document to filesignature.Sign("MetadataEncryptedText.docx",options);}
Implementation of encrypted Metadata signature over MetadataSignOptions encryption
This example shows how to sign document with encrypted Metadata signatures over .
using(Signaturesignature=newSignature("sample.docx")){// setup key and passphrasestringkey="1234567890";stringsalt="1234567890";// create data encryptionIDataEncryptionencryption=newSymmetricEncryption(SymmetricAlgorithmType.Rijndael,key,salt);// setup options with text of signatureMetadataSignOptionsoptions=newMetadataSignOptions(){// set encryption for all metadata signatures for this options// if you need separate encryption use own MetadataSignature.DataEncryption propertyDataEncryption=encryption};// setup signature metadataWordProcessingMetadataSignaturemdAuthor=newWordProcessingMetadataSignature("Author","Mr.Scherlock Holmes");// setup data of document idWordProcessingMetadataSignaturemdDocId=newWordProcessingMetadataSignature("DocumentId",Guid.NewGuid().ToString());// add signatures to optionsoptions.Signatures.Add(mdAuthor);options.Signatures.Add(mdDocId);// sign document to filesignature.Sign("MetadataEncryptedText.docx",options);}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: