use of org.xwiki.crypto.password.PasswordBasedCipher in project xwiki-commons by xwiki.
the class DefaultPrivateKeyPasswordBasedEncryptor method encrypt.
@Override
public byte[] encrypt(String algHint, byte[] password, KeyDerivationFunctionParameters kdfParameters, PrivateKeyParameters privateKey) throws GeneralSecurityException, IOException {
PasswordBasedCipherFactory factory = getPBEFactory(algHint);
PasswordBasedCipher cipher = factory.getInstance(true, new KeyWithIVParameters(password, factory.getIVSize(), this.randomProvider.get()), kdfParameters);
return encrypt(cipher, privateKey);
}
use of org.xwiki.crypto.password.PasswordBasedCipher in project xwiki-commons by xwiki.
the class DefaultPrivateKeyPasswordBasedEncryptor method encrypt.
@Override
public byte[] encrypt(byte[] password, PrivateKeyParameters privateKey) throws GeneralSecurityException, IOException {
PasswordBasedCipherFactory factory = getPBEFactory("PBES2-AES-CBC-Pad");
PasswordBasedCipher cipher = factory.getInstance(true, new KeyWithIVParameters(password, factory.getIVSize(), this.randomProvider.get()), new PBKDF2Parameters(this.randomProvider.get()));
return encrypt(cipher, privateKey);
}
use of org.xwiki.crypto.password.PasswordBasedCipher in project xwiki-commons by xwiki.
the class BcPBES2CipherFactory method getInstance.
@Override
public PasswordBasedCipher getInstance(boolean forEncryption, byte[] password, byte[] encoded) {
ASN1Sequence seq = ASN1Sequence.getInstance(encoded);
AlgorithmIdentifier alg = getPBES2AlgorithmIdentifier(seq);
PBES2Parameters params = PBES2Parameters.getInstance(alg.getParameters());
PasswordBasedCipherFactory pbecf = getPBES2CipherFactory(params.getEncryptionScheme());
PasswordBasedCipher cipher = getBcPBES2PasswordBasedCipher(pbecf, forEncryption, password, seq);
if (cipher != null) {
return cipher;
}
return pbecf.getInstance(forEncryption, password, encoded);
}
use of org.xwiki.crypto.password.PasswordBasedCipher in project xwiki-commons by xwiki.
the class BcPBES2CipherFactoryTest method PBESEncodeDecodeTest.
private void PBESEncodeDecodeTest(MockitoComponentMockingRule<? extends PasswordBasedCipherFactory> mocker, int blockSize, KeyDerivationFunctionParameters kdfParams) throws Exception {
PasswordBasedCipher encCipher = mocker.getComponentUnderTest().getInstance(true, new KeyWithIVParameters(PASSWORD, blockSize), kdfParams);
byte[] encoded = encCipher.doFinal(RSAKEY);
PasswordBasedCipher decCipher = factory.getInstance(false, PASSWORD, encCipher.getEncoded());
assertThat(decCipher.getEncoded(), equalTo(encCipher.getEncoded()));
assertThat(decCipher.doFinal(encoded), equalTo(RSAKEY));
}
Aggregations