Search for embedded and encrypted objects in Metadata signatures
Search for embedded and encrypted objects in Metadata signatures
Leave feedback
GroupDocs.Signature provides additional features when searching for Metadata Signatures (MetadataSignature) that were previously encrypted or contains custom data objects.
Ability to search for embedded custom objects into metadata and decrypt them to original source values.
Ability to search for encrypted text of metadata signature and decrypt it.
Here are the steps to search and decrypt previously encrypted text of metadata and decrypt custom object from metadata signature with GroupDocs.Signature API:
Implement if needed custom data serialization class that implement IDataSerializer interface. By default Signature uses embedded json format serialization but allows user to customize it. if object of class was serialized by custom serialization when searching for it, this class should also has same serialization attribute.
Implement if needed custom data encryption class that implements IDataEncryption interface. By default Signature has several encryption implementation you can use but allows user to customize it. There’s ability to specify inline encryption to use.
Process each Metadata signature and set property setDataEncryption to specify data encryption and call getData method to retrieve object.
Implementation of custom data serialization
This example shows how to specify custom serialization class. This class should be implemented as Attribute and IDataSerializerinterface.
/**
* 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
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 with serialization and encryption properties and setup Format attributes for properties.
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 metadata signatures
This example shows how to decrypt previously embedded encrypted custom objects into metadata signature. MetadataSignature contains method getData to retrieve object
// instantiating the signature object
Signaturesignature=newSignature("signed.pdf");// setup search options
MetadataSearchOptionssearchOptions=newMetadataSearchOptions();// search document
List<MetadataSignature>signatures=signature.search(MetadataSignature.class,searchOptions);// output signatures
for(MetadataSignaturemetadataSignature:signatures){if(metadataSignature!=null){DocumentSignatureDatadocSignature=metadataSignature.getData(DocumentSignatureData.class);if(docSignature!=null){System.out.print("Found DocumentSignature: #"+docSignature.getID()+" by "+docSignature.getAuthor()+" from "+docSignature.getSigned()+" DataFactor = "+docSignature.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.