How to resolve error Salt must be 8 bytes long

Swapneel picture Swapneel · Oct 8, 2016 · Viewed 7.7k times · Source

I am writing a program to sign a pdf using certificate (pfx file). For few of the certificates I am getting below exception.

java.security.InvalidAlgorithmParameterException: Salt must be at least 8 bytes long

This happens when I execute the below code.

Keystore ks = KeyStore.getInstance("pkcs12");

I am getting an exception in the below java file at line number 123. http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/com/sun/crypto/provider/HmacPKCS12PBESHA1.java?av=h

Answer

Navin Theruvingal picture Navin Theruvingal · Oct 10, 2016

Your keystore has one or more certificate(s) that has a salt length which is less than 8. The crypto program requires atleast 8 bytes.

I would recommend creating a new keystore with just the one certificate that you need and try signing with that.