added better check for PBE provided keyLength when required.
@@ -729,6 +729,10 @@ else if (ent.getType().equals(PRIVATE_KEY) || ent.getType().equals(PROTECTED_PRI
{
keySizeInBytes = params.getKeyLength().intValue();
}
+ else if (keySizeInBytes == -1)
+ {
+ throw new IOException("no keyLength found in ScryptParams");
+ }
return SCrypt.generate(Arrays.concatenate(encPassword, differentiator), params.getSalt(),
params.getCostParameter().intValue(), params.getBlockSize().intValue(),
params.getBlockSize().intValue(), keySizeInBytes);
@@ -741,6 +745,10 @@ else if (pbkdAlgorithm.getAlgorithm().equals(PKCSObjectIdentifiers.id_PBKDF2))
{
keySizeInBytes = pbkdf2Params.getKeyLength().intValue();
}
+ else if (keySizeInBytes == -1)
+ {
+ throw new IOException("no keyLength found in PBKDF2Params");
+ }
if (pbkdf2Params.getPrf().getAlgorithm().equals(PKCSObjectIdentifiers.id_hmacWithSHA512))
{
