Validating digital signature based on .p7s files
The digital
signature is a reality for many software applications. One typical format to
store the digital signature is using the .p7s file (https://www.reviversoft.com/en/file-extensions/p7s)
which contains information about how has signed a certain file, what algorithm
was utilized for signing, and also what is the hash of produced file.
In this
post we are going to demonstrate an example of how to validate a p7s file
signature when we have the original file and the .p7s file. First, we need a
library for this purpose. In this example we are going to use the demoiselle (https://github.com/demoiselle)
library.
For the example
we are going to execute you can download the dependency using maven, based on the
example below of pom.xml file:
<groupId>br.gov.frameworkdemoiselle</groupId>
<artifactId>demoiselle-core</artifactId>
<version>2.5.2</version>
</dependency>
<groupId>org.demoiselle.signer</groupId>
<artifactId>policy-impl-cades</artifactId>
<version>3.2.7</version>
</dependency>
Once we
have the dependency installed we can run the code for this validation importing the following
classes:
import org.demoiselle.signer.policy.impl.cades.SignatureInformations;
import org.demoiselle.signer.policy.impl.cades.pkcs7.impl.CAdESChecker;
Then, the method
below run the validation. Its interface receives as parameter the byte[] of original
data file and the .p7s file. The method checkDetattachedSignature will trigger an exception in case .p7s
is not a valid signature for .pdf file. In case the signature is validated,
then we can also extract several information from this p7s file, such as the
person that has signed the file, When it has happened, and also check the
signature HASHs.
}
}
}
}catch(Exception e){
return false;
return true;
You can download
the full example of this code here:
https://github.com/rafaelqg/code/blob/main/P7SValidator.java
You may see
a video class about this theme here:
Comments
Post a Comment