Search for embedded object with custom serialization of QR-Code signatures
Search for embedded object with custom serialization of QR-Code signatures
Leave feedback
GroupDocs.Signature provides following abilities to search for embedded data objects in QR-code signatures (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 interface.
Ensure that data class if defined with custom serialization attribute
This example shows how to specify custom serialization class. This class should be implemented as Attribute and IDataSerializer interface.
/**
* Creates class that implements IDataSerializer interface
* It cam support common serialization like JSon or custom data format
*/publicclassCustomSerializationAttributeimplementsIDataSerializer{public<T>Tdeserialize(Stringsource,Class<T>type){returnnewGson().fromJson(source,type);}publicStringserialize(Objectdata){returnnewGson().toJson(data);}}
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.
// Define class that implements IDataEncryption interface
// Class could inherits Attribute to use it with class definition
publicclassCustomXOREncryptionimplementsIDataEncryption{/**
* <p>
* Gets or sets non empty key for encryption (at least one character)
* </p>
*/publicfinalintgetKey(){returnauto_Key;}/**
* <p>
* Gets or sets non empty key for encryption (at least one character)
* </p>
*/publicfinalvoidsetKey(intvalue){auto_Key=value;}privateintauto_Key;/**
* <p>
* Encode method to encrypt string.
* </p>
* @return Returns enccrypted string
* @param source Source string to encode.
*/publicfinalStringencode(Stringsource){returnprocess(source);}/**
* <p>
* Decode method to obtain decrypted string.
* </p>
* @return Returns decrypted string
* @param source Source string to decode.
*/publicfinalStringdecode(Stringsource){returnprocess(source);}/**
* <p>
* Using XOR operation get encoded / decoded string
* </p>
* @return
* @param source
*/privateStringprocess(Stringsource){StringBuildersrc=newStringBuilder(source);StringBuilderdst=newStringBuilder(src.length());charchTmp;for(intindex=0;index<src.length();++index){chTmp=src.charAt(index);chTmp=(char)(chTmp^this.getKey());dst.append(chTmp);}returndst.toString();}}
Definition of class
This example shows how to define custom class for serialization.
publicstaticclassDocumentSignatureData{publicStringgetID(){returnID;}publicvoidsetID(Stringvalue){ID=value;}@FormatAttribute(propertyName="SignID")publicStringID;publicfinalStringgetAuthor(){returnAuthor;}publicfinalvoidsetAuthor(Stringvalue){Author=value;}@FormatAttribute(propertyName="SAuth")publicStringAuthor;//JAVA-added public wrapper for internalized property accessor
publicfinaljava.util.DategetSigned(){returnSigned;}publicfinalvoidsetSigned(java.util.Datevalue){Signed=value;}@FormatAttribute(propertyName="SDate",propertyFormat="yyyy-MM-dd")publicjava.util.DateSigned=newjava.util.Date();publicfinaljava.math.BigDecimalgetDataFactor(){returnDataFactor;}publicfinalvoidsetDataFactor(java.math.BigDecimalvalue){DataFactor=value;}@FormatAttribute(propertyName="SDFact",propertyFormat="N2")publicjava.math.BigDecimalDataFactor=newjava.math.BigDecimal(0.01);}
Search for embedded custom objects in QR-code signatures
This example shows how to decrypt previously embedded encrypted custom objects into QrCodeSignature contains method getData to retrieve object
Signaturesignature=newSignature("QRCodeCustomSerializationObject.pdf");// create data encryption
IDataEncryptionencryption=newCustomXOREncryption();QrCodeSearchOptionsoptions=newQrCodeSearchOptions();// specify special pages to search on
options.setAllPages(true);options.setDataEncryption(encryption);// search for signatures in document
List<QrCodeSignature>signatures=signature.search(QrCodeSignature.class,options);System.out.print("\nSource document contains following signatures:");for(QrCodeSignatureqrCodeSignature:signatures){System.out.print("QRCode signature found at page "+qrCodeSignature.getPageNumber()+" with type "+qrCodeSignature.getEncodeType());DocumentSignatureDatadocumentSignatureData=qrCodeSignature.getData(DocumentSignatureData.class);if(documentSignatureData!=null){System.out.print("QRCode signature has DocumentSignatureData object:\n ID = "+documentSignatureData.getID()+", Author = "+documentSignatureData.getAuthor()+", Signed = "+documentSignatureData.getSigned()+", DataFactor "+documentSignatureData.getDataFactor());}}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
Along with full-featured .NET library we provide simple, but powerful free Apps. You are welcome to eSign PDF, Word, Excel, PowerPoint documents with free to use online GroupDocs Signature App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.