Search in sources :

Example 1 with PasswordBasedCipherFactory

use of org.xwiki.crypto.password.PasswordBasedCipherFactory 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);
}
Also used : PasswordBasedCipherFactory(org.xwiki.crypto.password.PasswordBasedCipherFactory) PasswordBasedCipher(org.xwiki.crypto.password.PasswordBasedCipher) KeyWithIVParameters(org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters)

Example 2 with PasswordBasedCipherFactory

use of org.xwiki.crypto.password.PasswordBasedCipherFactory 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);
}
Also used : PasswordBasedCipherFactory(org.xwiki.crypto.password.PasswordBasedCipherFactory) PBKDF2Parameters(org.xwiki.crypto.password.params.PBKDF2Parameters) PasswordBasedCipher(org.xwiki.crypto.password.PasswordBasedCipher) KeyWithIVParameters(org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters)

Example 3 with PasswordBasedCipherFactory

use of org.xwiki.crypto.password.PasswordBasedCipherFactory 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);
}
Also used : PasswordBasedCipherFactory(org.xwiki.crypto.password.PasswordBasedCipherFactory) PBES2Parameters(org.xwiki.crypto.password.internal.kdf.PBES2Parameters) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) PasswordBasedCipher(org.xwiki.crypto.password.PasswordBasedCipher) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Aggregations

PasswordBasedCipher (org.xwiki.crypto.password.PasswordBasedCipher)3 PasswordBasedCipherFactory (org.xwiki.crypto.password.PasswordBasedCipherFactory)3 KeyWithIVParameters (org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters)2 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)1 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)1 PBES2Parameters (org.xwiki.crypto.password.internal.kdf.PBES2Parameters)1 PBKDF2Parameters (org.xwiki.crypto.password.params.PBKDF2Parameters)1