* Test compatibility of salt generator with salt size checking
* behaviour
*/
if (this.useLenientSaltSizeCheck) {
if (!this.saltGenerator.includePlainSaltInEncryptionResults()) {
throw new EncryptionInitializationException(
"The configured Salt Generator (" +
this.saltGenerator.getClass().getName() +
") does not include plain salt " +
"in encryption results, which is not compatible" +
"with setting the salt size checking behaviour to \"lenient\".");
}
}
/*
* MessageDigest is initialized the usual way, and the digester
* is marked as "initialized" so that configuration cannot be
* changed in the future.
*/
try {
if (this.provider != null) {
this.md =
MessageDigest.getInstance(
this.algorithm,
this.provider);
} else if (this.providerName != null) {
this.md =
MessageDigest.getInstance(
this.algorithm,
this.providerName);
} else {
this.md = MessageDigest.getInstance(this.algorithm);
}
} catch (NoSuchAlgorithmException e) {
throw new EncryptionInitializationException(e);
} catch (NoSuchProviderException e) {
throw new EncryptionInitializationException(e);
}
/*
* Store the digest length (algorithm-dependent) and check
* the operation is supported by the provider.
*/
this.digestLengthBytes = this.md.getDigestLength();
if (this.digestLengthBytes <= 0) {
throw new EncryptionInitializationException(
"The configured algorithm (" +
this.algorithm + ") or its provider do " +
"not allow knowing the digest length beforehand " +
"(getDigestLength() operation), which is not compatible" +
"with setting the salt size checking behaviour to \"lenient\".");