assertTrue(pbes2.getDefaultIterationCount() >= MINIMUM_ITERAION_COUNT);
assertTrue(pbes2.getDefaultSaltByteLength() >= MINIMUM_SALT_BYTE_LENGTH);
PbkdfKey key = new PbkdfKey("a password");
Headers headers = new Headers();
Key derivedKey = pbes2.deriveForEncrypt(key, headers);
assertThat(derivedKey.getEncoded().length, equalTo(16));
String saltInputString = headers.getStringHeaderValue(HeaderParameterNames.PBES2_SALT_INPUT);
byte[] saltInput = Base64Url.decode(saltInputString);
assertThat(saltInput.length, equalTo(pbes2.getDefaultSaltByteLength()));
Long iterationCount = headers.getLongHeaderValue(HeaderParameterNames.PBES2_ITERATION_COUNT);
assertThat(iterationCount, equalTo(pbes2.getDefaultIterationCount()));
Pbes2HmacShaWithAesKeyWrapAlgorithm newPbes2 = new Pbes2HmacShaWithAesKeyWrapAlgorithm.HmacSha256Aes128();
long newDefaultIterationCount = 1024;
newPbes2.setDefaultIterationCount(newDefaultIterationCount);
int newDefaultSaltByteLength = 16;
newPbes2.setDefaultSaltByteLength(newDefaultSaltByteLength);
headers = new Headers();
derivedKey = newPbes2.deriveForEncrypt(key, headers);
saltInputString = headers.getStringHeaderValue(HeaderParameterNames.PBES2_SALT_INPUT);
saltInput = Base64Url.decode(saltInputString);
assertThat(saltInput.length, equalTo(newDefaultSaltByteLength));
iterationCount = headers.getLongHeaderValue(HeaderParameterNames.PBES2_ITERATION_COUNT);
assertThat(iterationCount, equalTo(newDefaultIterationCount));
assertThat(derivedKey.getEncoded().length, equalTo(16));
}