Search in sources :

Example 1 with ScryptParameters

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()));
}
Also used : KeyDerivationFunction(org.xwiki.crypto.password.KeyDerivationFunction) ScryptParameters(org.xwiki.crypto.password.params.ScryptParameters) KeyWithIVParameters(org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters) Test(org.junit.Test)

Example 2 with ScryptParameters

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()));
}
Also used : KeyDerivationFunction(org.xwiki.crypto.password.KeyDerivationFunction) ScryptParameters(org.xwiki.crypto.password.params.ScryptParameters) KeyWithIVParameters(org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters) Test(org.junit.Test)

Example 3 with ScryptParameters

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()));
}
Also used : ScryptKDFParams(org.xwiki.crypto.password.internal.kdf.ScryptKDFParams) KeyDerivationFunc(org.bouncycastle.asn1.pkcs.KeyDerivationFunc) ScryptParameters(org.xwiki.crypto.password.params.ScryptParameters)

Aggregations

ScryptParameters (org.xwiki.crypto.password.params.ScryptParameters)3 Test (org.junit.Test)2 KeyWithIVParameters (org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters)2 KeyDerivationFunction (org.xwiki.crypto.password.KeyDerivationFunction)2 KeyDerivationFunc (org.bouncycastle.asn1.pkcs.KeyDerivationFunc)1 ScryptKDFParams (org.xwiki.crypto.password.internal.kdf.ScryptKDFParams)1