Search in sources :

Example 1 with ParametersWithRandom

use of org.gudy.bouncycastle.crypto.params.ParametersWithRandom in project BiglyBT by BiglySoftware.

the class ECDSASigner method init.

@Override
public void init(boolean forSigning, CipherParameters param) {
    if (forSigning) {
        if (param instanceof ParametersWithRandom) {
            ParametersWithRandom rParam = (ParametersWithRandom) param;
            this.random = rParam.getRandom();
            this.key = (ECPrivateKeyParameters) rParam.getParameters();
        } else {
            this.random = new SecureRandom();
            this.key = (ECPrivateKeyParameters) param;
        }
    } else {
        this.key = (ECPublicKeyParameters) param;
    }
}
Also used : ParametersWithRandom(org.gudy.bouncycastle.crypto.params.ParametersWithRandom) SecureRandom(java.security.SecureRandom)

Example 2 with ParametersWithRandom

use of org.gudy.bouncycastle.crypto.params.ParametersWithRandom in project BiglyBT by BiglySoftware.

the class PaddedBufferedBlockCipher method init.

/**
 * initialise the cipher.
 *
 * @param forEncryption if true the cipher is initialised for
 *  encryption, if false for decryption.
 * @param params the key and other data required by the cipher.
 * @exception IllegalArgumentException if the params argument is
 * inappropriate.
 */
@Override
public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException {
    this.forEncryption = forEncryption;
    reset();
    if (params instanceof ParametersWithRandom) {
        ParametersWithRandom p = (ParametersWithRandom) params;
        padding.init(p.getRandom());
        cipher.init(forEncryption, p.getParameters());
    } else {
        padding.init(null);
        cipher.init(forEncryption, params);
    }
}
Also used : ParametersWithRandom(org.gudy.bouncycastle.crypto.params.ParametersWithRandom)

Example 3 with ParametersWithRandom

use of org.gudy.bouncycastle.crypto.params.ParametersWithRandom in project BiglyBT by BiglySoftware.

the class JDKDSASigner method engineInitSign.

@Override
protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
    CipherParameters param = null;
    if (privateKey instanceof ECKey) {
        param = ECUtil.generatePrivateKeyParameter(privateKey);
    } else {
        param = DSAUtil.generatePrivateKeyParameter(privateKey);
    }
    digest.reset();
    if (random != null) {
        signer.init(true, new ParametersWithRandom(param, random));
    } else {
        signer.init(true, param);
    }
}
Also used : CipherParameters(org.gudy.bouncycastle.crypto.CipherParameters) ParametersWithRandom(org.gudy.bouncycastle.crypto.params.ParametersWithRandom) ECKey(org.gudy.bouncycastle.jce.interfaces.ECKey)

Example 4 with ParametersWithRandom

use of org.gudy.bouncycastle.crypto.params.ParametersWithRandom in project BiglyBT by BiglySoftware.

the class ISO9796d1Encoding method init.

@Override
public void init(boolean forEncryption, CipherParameters param) {
    RSAKeyParameters kParam = null;
    if (param instanceof ParametersWithRandom) {
        ParametersWithRandom rParam = (ParametersWithRandom) param;
        kParam = (RSAKeyParameters) rParam.getParameters();
    } else {
        kParam = (RSAKeyParameters) param;
    }
    engine.init(forEncryption, kParam);
    bitSize = kParam.getModulus().bitLength();
    this.forEncryption = forEncryption;
}
Also used : ParametersWithRandom(org.gudy.bouncycastle.crypto.params.ParametersWithRandom) RSAKeyParameters(org.gudy.bouncycastle.crypto.params.RSAKeyParameters)

Example 5 with ParametersWithRandom

use of org.gudy.bouncycastle.crypto.params.ParametersWithRandom in project BiglyBT by BiglySoftware.

the class PKCS1Encoding method init.

@Override
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, kParam);
    this.forPrivateKey = kParam.isPrivate();
    this.forEncryption = forEncryption;
}
Also used : AsymmetricKeyParameter(org.gudy.bouncycastle.crypto.params.AsymmetricKeyParameter) ParametersWithRandom(org.gudy.bouncycastle.crypto.params.ParametersWithRandom) SecureRandom(java.security.SecureRandom)

Aggregations

ParametersWithRandom (org.gudy.bouncycastle.crypto.params.ParametersWithRandom)6 SecureRandom (java.security.SecureRandom)3 AsymmetricKeyParameter (org.gudy.bouncycastle.crypto.params.AsymmetricKeyParameter)2 CipherParameters (org.gudy.bouncycastle.crypto.CipherParameters)1 RSAKeyParameters (org.gudy.bouncycastle.crypto.params.RSAKeyParameters)1 ECKey (org.gudy.bouncycastle.jce.interfaces.ECKey)1