-1

I'm attempting to read the date of digital signatures in a PDF document using the following code:

try {
    final PdfReader reader = new PdfReader(this.etimesheet.getAbsolutePath());
    final AcroFields fields - reader.getAcroFields();
    if (fields != null) {
        final ArrayList names - fields.getSignatureNames();
        for (int k=0; k < names.size(); ++k) {
            String name = (String)names.get(k);
            PdfPKCS7 pk = fields.verifySignature(name); // Code starts generating Warnings here
            // Calendar cal = pk.getSignDate();
         }
         ...

After adding the PdfPKSCS7 line, I receive the warning "ExceptionConverter: java.security.NoSuchAlgorithmException: SHA256 MessageDigest not available".

What do I need to resolve this issue, or is there another way to extract the date from a digital signature?

user620597
  • 21
  • 2
  • Have you registered BouncyCastle as security provider? – mkl May 17 '16 at 07:37
  • I don't believe that I was. I did search for [register BouncyCastle as security provider](https://www.google.com/search?q=egister+BouncyCastle+as+security+provider&ie=utf-8&oe=utf-8). Adding `import org.bouncycastle.jce.provider.BouncyCastleProvider;` and `Security.addProvider(new BouncyCastleProvider());` now allows me to getSignDate(). Thanks. Ref: [Provider Installation - Java APIs 1.X - The Legion of the Bouncy Castle](http://www.bouncycastle.org/wiki/display/JA1/Provider+Installation) - **Installing the Provider Dynamically**. – user620597 May 17 '16 at 10:56
  • Ok, I made my original comment an answer. – mkl May 17 '16 at 21:41

1 Answers1

0

The OP experienced an

ExceptionConverter: java.security.NoSuchAlgorithmException: SHA256 MessageDigest not available

exception. Depending on the library and JRE versions involved this means that neither the "Unlimited Strength Java(TM) Cryptography Extension Policy Files" have been installed nor Bouncy Castle has been registered as security provider.

If your application uses any java.security stuff, it is always a good idea to do the former. Furthermore, if you do not have installed any other additional security provider, you most likely will profit from installing and registering the BouncyCastle security provider.

As the OP google'd, the site BouncyCastle Provider Installation will show how to do the latter:

Installing the Provider Dynamically

import org.bouncycastle.jce.provider.BouncyCastleProvider;

...

Security.addProvider(new BouncyCastleProvider());

mkl
  • 90,588
  • 15
  • 125
  • 265