use of org.xwiki.crypto.password.params.ScryptParameters 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()));
}
use of org.xwiki.crypto.password.params.ScryptParameters in project xwiki-commons by xwiki.
the class DefaultKeyDerivationFunctionFactoryTest method ScryptDecodingTest.
@Test
public void ScryptDecodingTest() throws Exception {
byte[] password = PasswordToByteConverter.convert("password");
byte[] encoded = Base64.decode("MCwGCSsGAQQB2kcECzAfBBAcO15L0rQ01O2RJ5UhyqCdAgICAAIBEAIBAgIBIA==");
KeyDerivationFunction kdf = getKDFInstance(new ScryptParameters(32, 512, 2, 16, 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.params.ScryptParameters in project xwiki-commons by xwiki.
the class BcScryptKeyDerivationFunctionFactory method getInstance.
@Override
public KeyDerivationFunction getInstance(ASN1Encodable parameters) {
KeyDerivationFunc kdf = KeyDerivationFunc.getInstance(parameters);
if (!kdf.getAlgorithm().equals(ALG_ID)) {
throw new IllegalArgumentException("Illegal algorithm identifier for Scrypt: " + kdf.getAlgorithm().getId());
}
ScryptKDFParams params = ScryptKDFParams.getInstance(kdf.getParameters());
return getInstance(new ScryptParameters((params.getKeyLength() != null) ? params.getKeyLength().intValue() : -1, params.getCostParameter().intValue(), params.getParallelizationParameter().intValue(), params.getBlockSize().intValue(), params.getSalt()));
}
Aggregations