use of org.xwiki.crypto.password.KeyDerivationFunction in project xwiki-commons by xwiki.
the class DefaultKeyDerivationFunctionFactory method getInstance.
@Override
public KeyDerivationFunction getInstance(byte[] encoded) {
KeyDerivationFunc func = KeyDerivationFunc.getInstance(ASN1Sequence.getInstance(encoded));
KeyDerivationFunctionFactory factory = getFactory(func.getAlgorithm().getId());
KeyDerivationFunction kdf = getBcInstance(factory, func);
if (kdf == null) {
kdf = factory.getInstance(encoded);
}
return kdf;
}
use of org.xwiki.crypto.password.KeyDerivationFunction 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.password.KeyDerivationFunction 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.password.KeyDerivationFunction in project xwiki-commons by xwiki.
the class BcPBES2AesCipherFactory method getInstance.
@Override
protected PasswordBasedCipher getInstance(boolean forEncryption, byte[] password, KeyDerivationFunc kdfParams, EncryptionScheme scheme) {
KeyDerivationFunction kdf = getKeyDerivationFunction(kdfParams);
// Set key size according to the encryption scheme algorithm used.
kdf.overrideKeySize(getAESKeySize(scheme.getAlgorithm()));
return getPasswordBasedCipher(forEncryption, kdf, new KeyWithIVParameters(kdf.derive(password).getKey(), ((ASN1OctetString) scheme.getParameters()).getOctets()));
}
use of org.xwiki.crypto.password.KeyDerivationFunction in project xwiki-commons by xwiki.
the class BcScryptKeyDerivationFunctionFactoryTest method scryptSerializationDeserializationTest.
@Test
public void scryptSerializationDeserializationTest() throws Exception {
byte[] password = PasswordToByteConverter.convert("password");
KeyDerivationFunction kdf = getKDFInstance(new ScryptParameters(64, 512, 8));
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()));
}
Aggregations