Search in sources :

Example 11 with ParametersWithRandom

use of org.bouncycastle.crypto.params.ParametersWithRandom in project robovm by robovm.

the class RSACoreEngine method init.

/**
     * initialise the RSA engine.
     *
     * @param forEncryption true if we are encrypting, false otherwise.
     * @param param the necessary RSA key parameters.
     */
public void init(boolean forEncryption, CipherParameters param) {
    if (param instanceof ParametersWithRandom) {
        ParametersWithRandom rParam = (ParametersWithRandom) param;
        key = (RSAKeyParameters) rParam.getParameters();
    } else {
        key = (RSAKeyParameters) param;
    }
    this.forEncryption = forEncryption;
}
Also used : ParametersWithRandom(org.bouncycastle.crypto.params.ParametersWithRandom)

Example 12 with ParametersWithRandom

use of org.bouncycastle.crypto.params.ParametersWithRandom in project robovm by robovm.

the class DHBasicAgreement method init.

public void init(CipherParameters param) {
    AsymmetricKeyParameter kParam;
    if (param instanceof ParametersWithRandom) {
        ParametersWithRandom rParam = (ParametersWithRandom) param;
        kParam = (AsymmetricKeyParameter) rParam.getParameters();
    } else {
        kParam = (AsymmetricKeyParameter) param;
    }
    if (!(kParam instanceof DHPrivateKeyParameters)) {
        throw new IllegalArgumentException("DHEngine expects DHPrivateKeyParameters");
    }
    this.key = (DHPrivateKeyParameters) kParam;
    this.dhParams = key.getParameters();
}
Also used : AsymmetricKeyParameter(org.bouncycastle.crypto.params.AsymmetricKeyParameter) DHPrivateKeyParameters(org.bouncycastle.crypto.params.DHPrivateKeyParameters) ParametersWithRandom(org.bouncycastle.crypto.params.ParametersWithRandom)

Example 13 with ParametersWithRandom

use of org.bouncycastle.crypto.params.ParametersWithRandom in project robovm by robovm.

the class OAEPEncoding method init.

public void init(boolean forEncryption, CipherParameters param) {
    if (param instanceof ParametersWithRandom) {
        ParametersWithRandom rParam = (ParametersWithRandom) param;
        this.random = rParam.getRandom();
    } else {
        this.random = new SecureRandom();
    }
    engine.init(forEncryption, param);
    this.forEncryption = forEncryption;
}
Also used : ParametersWithRandom(org.bouncycastle.crypto.params.ParametersWithRandom) SecureRandom(java.security.SecureRandom)

Example 14 with ParametersWithRandom

use of org.bouncycastle.crypto.params.ParametersWithRandom in project robovm by robovm.

the class PKCS1Encoding method init.

public void init(boolean forEncryption, CipherParameters param) {
    AsymmetricKeyParameter kParam;
    if (param instanceof ParametersWithRandom) {
        ParametersWithRandom rParam = (ParametersWithRandom) param;
        this.random = rParam.getRandom();
        kParam = (AsymmetricKeyParameter) rParam.getParameters();
    } else {
        this.random = new SecureRandom();
        kParam = (AsymmetricKeyParameter) param;
    }
    engine.init(forEncryption, param);
    this.forPrivateKey = kParam.isPrivate();
    this.forEncryption = forEncryption;
}
Also used : AsymmetricKeyParameter(org.bouncycastle.crypto.params.AsymmetricKeyParameter) ParametersWithRandom(org.bouncycastle.crypto.params.ParametersWithRandom) SecureRandom(java.security.SecureRandom)

Example 15 with ParametersWithRandom

use of org.bouncycastle.crypto.params.ParametersWithRandom in project XobotOS by xamarin.

the class Signature method engineInitSign.

protected void engineInitSign(PrivateKey privateKey, SecureRandom random) throws InvalidKeyException {
    CipherParameters param;
    if (privateKey instanceof ECKey) {
        param = ECUtil.generatePrivateKeyParameter(privateKey);
    } else {
        throw new InvalidKeyException("can't recognise key type in ECDSA based signer");
    }
    digest.reset();
    if (random != null) {
        signer.init(true, new ParametersWithRandom(param, random));
    } else {
        signer.init(true, param);
    }
}
Also used : CipherParameters(org.bouncycastle.crypto.CipherParameters) ParametersWithRandom(org.bouncycastle.crypto.params.ParametersWithRandom) ECKey(org.bouncycastle.jce.interfaces.ECKey) InvalidKeyException(java.security.InvalidKeyException)

Aggregations

ParametersWithRandom (org.bouncycastle.crypto.params.ParametersWithRandom)41 SecureRandom (java.security.SecureRandom)20 CipherParameters (org.bouncycastle.crypto.CipherParameters)12 AsymmetricKeyParameter (org.bouncycastle.crypto.params.AsymmetricKeyParameter)8 InvalidKeyException (java.security.InvalidKeyException)7 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)5 InvalidParameterException (java.security.InvalidParameterException)5 KeyParameter (org.bouncycastle.crypto.params.KeyParameter)5 ParametersWithIV (org.bouncycastle.crypto.params.ParametersWithIV)5 ParametersWithID (org.bouncycastle.crypto.params.ParametersWithID)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 BadPaddingException (javax.crypto.BadPaddingException)3 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)3 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)3 SecretKey (javax.crypto.SecretKey)3 ShortBufferException (javax.crypto.ShortBufferException)3 IvParameterSpec (javax.crypto.spec.IvParameterSpec)3 PBEParameterSpec (javax.crypto.spec.PBEParameterSpec)3 DataLengthException (org.bouncycastle.crypto.DataLengthException)3 InvalidCipherTextException (org.bouncycastle.crypto.InvalidCipherTextException)3