# Search for embedded object with custom serialization of QR-Code signatures This article explains how to search for embedded electronic signatures with custom serialization in QR code electronic signatures. This topic contains example of custom serialization, class definition and search for serialized objects in the QR-codes with GroupDocs.Signature. [**GroupDocs.Signature**](https://products.groupdocs.com/signature/net) provides following abilities to search for embedded data objects in QR-code signatures ([QrCodeSignature](https://reference.groupdocs.com/signature/net/groupdocs.signature.domain/qrcodesignature)) that were embedded with custom encryption and serialization * ability to search for embedded custom objects into metadata and decrypt them to original source values * ability to search for custom encrypted QR-code signature and decrypt it * ability to search for custom serialized QR-code signatures Here are the steps to search and decrypt previously encrypted text of QR-Code and decrypt custom object from QR-Code signature with GroupDocs.Signature API: * Implement (use) custom data serialization class that implements [IDataEncryption](https://reference.groupdocs.com/signature/net/groupdocs.signature.domain.extensions/idataencryption) interface. * Ensure that data class if defined with custom serialization attribute * Instantiate the [QrCodeSearchOptions](https://reference.groupdocs.com/signature/net/groupdocs.signature.options/qrcodesearchoptions) object and setup [DataEncryption](https://reference.groupdocs.com/signature/net/groupdocs.signature.options/qrcodesearchoptions/dataencryption) value with custom encryption object implementation * Call [Search](https://reference.groupdocs.com/signature/net/groupdocs.signature/signature/search) method of [Signature](https://reference.groupdocs.com/signature/net/groupdocs.signature/signature) class instance and pass [QrCodeSearchOptions](https://reference.groupdocs.com/signature/net/groupdocs.signature.options/qrcodesearchoptions) to it. ## Implementation of custom data serialization  This example shows how to specify custom serialization class. This class should be implemented as Attribute and [IDataSerializer](https://reference.groupdocs.com/signature/net/groupdocs.signature.domain.extensions/idataserializer) interface. ```csharp /// /// Creates class that implements IDataSerializer interface /// This implementation is using json library to provide serialization and deserialization /// public class CustomSerializationAttribute : Attribute, IDataSerializer { public T Deserialize(string source) where T : class { return JsonConvert.DeserializeObject(source); } public string Serialize(object data) { var serializerSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; return JsonConvert.SerializeObject(data, serializerSettings); } } ``` ## Implementation of custom data encryption This example shows how to specify custom serialization class. This class could be implemented also as Attribute (optional) to specify as class attribute. ```csharp // Define class that implements IDataEncryption interface // Class could inherits Attribute to use it with class definition public class CustomXOREncryption : IDataEncryption { /// /// Gets or sets non empty key for encryption (at least one character) /// public int Key { get; set; } /// /// Encode method to encrypt string. /// /// Source string to encode. /// Returns encrypted string public string Encode(string source) { return Process(source); } /// /// Decode method to obtain decrypted string. /// /// Source string to decode. /// Returns decrypted string public string Decode(string source) { return Process(source); } /// /// Using XOR operation get encoded / decoded string /// /// /// private string Process(string source) { StringBuilder src = new StringBuilder(source); StringBuilder dst = new StringBuilder(src.Length); char chTmp; for (int index = 0; index < src.Length; ++index) { chTmp = src[index]; chTmp = (char)(chTmp ^ this.Key); dst.Append(chTmp); } return dst.ToString(); } } ``` ## Definition of class This example shows how to define custom class for serialization. ```csharp // define class with custom serialization attribute [CustomSerialization] public class DocumentSignatureData { [Format("SignID")] public string ID { get; set; } [Format("SAuth")] public string Author { get; set; } [Format("SDate", "yyyy-MM-dd")] public DateTime Signed { get; set; } [Format("SDFact", "N2")] public decimal DataFactor { get; set; } [SkipSerialization] public string Comments { get; set; } } ``` ## Search for embedded custom objects in QR-code signatures This example shows how to decrypt previously embedded encrypted custom objects into [QrCodeSignature](https://reference.groupdocs.com/signature/net/groupdocs.signature.domain/qrcodesignature) contains method [GetData](https://reference.groupdocs.com/signature/net/groupdocs.signature.domain/qrcodesignature/getdata) to retrieve object ```csharp using (Signature signature = new Signature("QRCodeCustomSerializationObject.pdf")) { // create data encryption IDataEncryption encryption = new CustomXOREncryption(); QrCodeSearchOptions options = new QrCodeSearchOptions() { // specify special pages to search on AllPages = true, DataEncryption = encryption }; // search for signatures in document List signatures = signature.Search(options); Console.WriteLine("\nSource document contains following signatures:"); foreach (var qrCodeSignature in signatures) { Console.WriteLine("QRCode signature found at page {0} with type {1}.", qrCodeSignature.PageNumber, qrCodeSignature.EncodeType); DocumentSignatureData documentSignatureData = qrCodeSignature.GetData(); if (documentSignatureData != null) { Console.WriteLine("QRCode signature has DocumentSignatureData object:\n ID = {0}, Author = {1}, Signed = {2}, DataFactor {3}", documentSignatureData.ID, documentSignatureData.Author, documentSignatureData.Signed.ToShortDateString(), documentSignatureData.DataFactor); } } } ``` ## More resources ### GitHub Examples You may easily run the code above and see the feature in action in our GitHub examples: * [GroupDocs.Signature for .NET examples, plugins, and showcase](https://github.com/groupdocs-signature/GroupDocs.Signature-for-.NET) * [GroupDocs.Signature for Java examples, plugins, and showcase](https://github.com/groupdocs-signature/GroupDocs.Signature-for-Java) * [Document Signature for .NET MVC UI Example](https://github.com/groupdocs-signature/GroupDocs.Signature-for-.NET-MVC) * [Document Signature for .NET App WebForms UI Example](https://github.com/groupdocs-signature/GroupDocs.Signature-for-.NET-WebForms) * [Document Signature for Java App Dropwizard UI Example](https://github.com/groupdocs-signature/GroupDocs.Signature-for-Java-Dropwizard) * [Document Signature for Java Spring UI Example](https://github.com/groupdocs-signature/GroupDocs.Signature-for-Java-Spring) ### Free Online Apps Along with the full-featured .NET library, we provide simple but powerful free online apps. To sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the **[GroupDocs.Signature App Product Family](https://products.groupdocs.app/signature/family)**.