throws Exception
{
byte[] utf8K = Hex.decode(utf8);
byte[] ascK = Hex.decode(eightBit);
SecretKeyFactory f = SecretKeyFactory.getInstance(baseAlg, "BC");
KeySpec ks1 = new PBEKeySpec("\u0141\u0142".toCharArray(), new byte[20], 4096, 160);
if (!Arrays.areEqual((defIsUTF8) ? utf8K : ascK, f.generateSecret(ks1).getEncoded()))
{
fail(baseAlg + " wrong PBKDF2 k1 key generated, got : " + new String(Hex.encode(f.generateSecret(ks1).getEncoded())));
}
KeySpec ks2 = new PBEKeySpec("\u0041\u0042".toCharArray(), new byte[20], 4096, 160);
if (!Arrays.areEqual(ascK, f.generateSecret(ks2).getEncoded()))
{
fail(baseAlg + " wrong PBKDF2 k2 key generated");
}
f = SecretKeyFactory.getInstance(baseAlg + "AndUTF8", "BC");
ks1 = new PBEKeySpec("\u0141\u0142".toCharArray(), new byte[20], 4096, 160);
if (!Arrays.areEqual(utf8K, f.generateSecret(ks1).getEncoded()))
{
fail(baseAlg + " wrong PBKDF2 k1 utf8 key generated");
}
ks2 = new PBEKeySpec("\u0041\u0042".toCharArray(), new byte[20], 4096, 160);
if (!Arrays.areEqual(ascK, f.generateSecret(ks2).getEncoded()))
{
fail(baseAlg + " wrong PBKDF2 k2 utf8 key generated");
}
f = SecretKeyFactory.getInstance(baseAlg + "And8BIT", "BC");
ks1 = new PBEKeySpec("\u0141\u0142".toCharArray(), new byte[20], 4096, 160);
if (!Arrays.areEqual(ascK, f.generateSecret(ks1).getEncoded()))
{
fail(baseAlg + " wrong PBKDF2 k1 8bit key generated");
}
ks2 = new PBEKeySpec("\u0041\u0042".toCharArray(), new byte[20], 4096, 160);
if (!Arrays.areEqual(ascK, f.generateSecret(ks2).getEncoded()))
{
fail(baseAlg + " wrong PBKDF2 k2 8bit key generated");
}
}