Implement custom serialization with QR-Code signatures
Leave feedback
GroupDocs.Signature provides ability to embed into QR-code signature custom objects. This feature is implemented over object serialization to string and further encryption. There is ability to provide custom encryption. This procedure requires implementation of interface IDataEncryption with two methods to encrypt and decrypt data.
Here are the steps to embed into QR-code text with custom encryption with GroupDocs.Signature:
Define custom data encryption class that implements IDataEncryption interface. By default GroupDocs.Signature has several encryption implementation you can use but allows user to customize it.
Implement class with properties and specify if needed class attributes (like custom serialization attribute, custom encryption attribute), specify attributes for properties like FormatAttribute attribute to specify serialization name and display format, same as SkipSerializationAttribute to mark property of class as not serialize
Create new instance of Signature class and pass source document path as a constructor parameter.
This example shows how to specify custom serialization class. This class could be implemented also as Attribute (optional) to specify as class attribute.
This example shows how to define custom class with serialization and encryption properties and setup Format attributes for properties.
// setup CustomSerialization Attribute to setup customer serialization(see example above)[CustomSerialization]publicclassDocumentSignatureData{ [Format("SignID")]publicstringID{get;set;} [Format("SAuth")]publicstringAuthor{get;set;} [Format("SDate", "yyyy-MM-dd")]publicDateTimeSigned{get;set;} [Format("SDFact", "N2")]publicdecimalDataFactor{get;set;} [SkipSerialization]publicstringComments{get;set;}}
Sign documents with custom encrypted objects and values into QR-code signatures
This example shows how to add custom object into metadata signature to Image document.
using(Signaturesignature=newSignature("sample.pdf")){// create data encryptionIDataEncryptionencryption=newCustomXOREncryption();// create custom objectDocumentSignatureDatadocumentSignatureData=newDocumentSignatureData(){ID=Guid.NewGuid().ToString(),Author=Environment.UserName,Signed=DateTime.Now,DataFactor=11.22M};// setup QR-Code optionsQrCodeSignOptionsoptions=newQrCodeSignOptions(){// set custom object to serialize to QR CodeData=documentSignatureData,// QR-code typeEncodeType=QrCodeTypes.QR,// specify serialization encryptionDataEncryption=encryption,// locate and aligh signatureHeight=100,Width=100,VerticalAlignment=VerticalAlignment.Bottom,HorizontalAlignment=HorizontalAlignment.Right,Margin=newPadding(){Right=10,Bottom=10}};// sign document to filesignature.Sign("QRCodeCustomSerialization.pdf",options);}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: