use of org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters in project xwiki-commons by xwiki.
the class BcPKCS5S2KeyDerivationFunctionFactoryTest method pbkdf2SerializationDeserializationTest.
@Test
public void pbkdf2SerializationDeserializationTest() throws Exception {
byte[] password = PasswordToByteConverter.convert("password");
KeyDerivationFunction kdf = getKDFInstance(new PBKDF2Parameters(32, 1000));
KeyWithIVParameters params = kdf.derive(password, 8);
KeyDerivationFunction kdf2 = factory.getInstance(kdf.getEncoded());
KeyWithIVParameters params2 = kdf2.derive(password, 8);
assertThat(params.getKey(), equalTo(params2.getKey()));
assertThat(params2.getIV(), equalTo(params2.getIV()));
}
use of org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters in project xwiki-commons by xwiki.
the class BcPKCS5S2KeyDerivationFunctionFactoryTest method pbkdf2KeyWithIVWithRandomSalt.
@Test
public void pbkdf2KeyWithIVWithRandomSalt() throws Exception {
byte[] password = PasswordToByteConverter.convert("password");
PBKDF2Parameters kdfParam1 = new PBKDF2Parameters(32, 5);
KeyWithIVParameters params1 = getKDFInstance(kdfParam1).derive(password, 16);
PBKDF2Parameters kdfParam2 = new PBKDF2Parameters(32, 5);
KeyWithIVParameters params2 = getKDFInstance(kdfParam2).derive(password, 16);
assertThat(params1.getKey(), not(equalTo(params2.getKey())));
assertThat(params1.getKey().length, equalTo(32));
assertThat(params1.getIV().length, equalTo(16));
assertThat(kdfParam1.getIterationCount(), equalTo(kdfParam2.getIterationCount()));
assertThat(kdfParam1.getSalt(), not(equalTo(kdfParam2.getSalt())));
}
use of org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters in project xwiki-commons by xwiki.
the class BcPKCS5S2KeyDerivationFunctionFactoryTest method pbkdf2KeyWithIVWithRandomIterationCount.
@Test
public void pbkdf2KeyWithIVWithRandomIterationCount() throws Exception {
byte[] salt = Hex.decode("12 34 56 78 78 56 34 12");
byte[] password = PasswordToByteConverter.convert("password");
PBKDF2Parameters kdfParam1 = new PBKDF2Parameters(24, salt);
KeyWithIVParameters params1 = getKDFInstance(kdfParam1).derive(password, 12);
PBKDF2Parameters kdfParam2 = new PBKDF2Parameters(24, salt);
KeyWithIVParameters params2 = getKDFInstance(kdfParam2).derive(password, 12);
assertThat(params1.getKey(), not(equalTo(params2.getKey())));
assertThat(params1.getKey().length, equalTo(24));
assertThat(params1.getIV().length, equalTo(12));
assertThat(kdfParam1.getSalt(), equalTo(kdfParam2.getSalt()));
assertThat(kdfParam1.getIterationCount(), not(equalTo(kdfParam2.getIterationCount())));
}
use of org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters in project xwiki-commons by xwiki.
the class DefaultKeyDerivationFunctionFactoryTest method Pbkdf2DecodingTest.
@Test
public void Pbkdf2DecodingTest() throws Exception {
byte[] password = PasswordToByteConverter.convert("password");
byte[] encoded = Base64.decode("MCYGCSqGSIb3DQEFDDAZBBAcO15L0rQ01O2RJ5UhyqCdAgID6AIBIA==");
KeyDerivationFunction kdf = getKDFInstance(new PBKDF2Parameters(32, 1000, Hex.decode("1c3b5e4bd2b434d4ed91279521caa09d")));
KeyWithIVParameters params = kdf.derive(password, 8);
KeyDerivationFunction kdf2 = factory.getInstance(encoded);
KeyWithIVParameters params2 = kdf2.derive(password, 8);
assertThat(kdf.getEncoded(), equalTo(encoded));
assertThat(params.getKey(), equalTo(params2.getKey()));
assertThat(params2.getIV(), equalTo(params2.getIV()));
}
use of org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters in project xwiki-commons by xwiki.
the class AbstractBcPBKDF2 method derive.
@Override
public KeyWithIVParameters derive(byte[] password, int ivSize) {
this.generator.init(password, this.parameters.getSalt(), this.parameters.getIterationCount());
ParametersWithIV keyParam = (ParametersWithIV) this.generator.generateDerivedParameters(getKeySize() * 8, ivSize * 8);
return new KeyWithIVParameters(((KeyParameter) keyParam.getParameters()).getKey(), keyParam.getIV());
}
Aggregations