Search in sources :

Example 1 with ParametersWithRandom

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

the class JDKDSASigner method engineInitSign.

protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
    CipherParameters param;
    // BEGIN android-removed
    // if (privateKey instanceof GOST3410Key)
    // {
    //     param = GOST3410Util.generatePrivateKeyParameter(privateKey);
    // }
    // else
    // {
    // END android-removed
    param = DSAUtil.generatePrivateKeyParameter(privateKey);
    if (random != null) {
        param = new ParametersWithRandom(param, random);
    }
    digest.reset();
    signer.init(true, param);
}
Also used : CipherParameters(org.bouncycastle.crypto.CipherParameters) ParametersWithRandom(org.bouncycastle.crypto.params.ParametersWithRandom)

Example 2 with ParametersWithRandom

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

the class RSADigestSigner method init.

/**
     * initialise the signer for signing or verification.
     *
     * @param forSigning
     *            true if for signing, false otherwise
     * @param parameters
     *            necessary parameters.
     */
public void init(boolean forSigning, CipherParameters parameters) {
    this.forSigning = forSigning;
    AsymmetricKeyParameter k;
    if (parameters instanceof ParametersWithRandom) {
        k = (AsymmetricKeyParameter) ((ParametersWithRandom) parameters).getParameters();
    } else {
        k = (AsymmetricKeyParameter) parameters;
    }
    if (forSigning && !k.isPrivate()) {
        throw new IllegalArgumentException("signing requires private key");
    }
    if (!forSigning && k.isPrivate()) {
        throw new IllegalArgumentException("verification requires public key");
    }
    reset();
    rsaEngine.init(forSigning, parameters);
}
Also used : AsymmetricKeyParameter(org.bouncycastle.crypto.params.AsymmetricKeyParameter) ParametersWithRandom(org.bouncycastle.crypto.params.ParametersWithRandom)

Example 3 with ParametersWithRandom

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

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 4 with ParametersWithRandom

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

the class RSABlindedEngine 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) {
    core.init(forEncryption, param);
    if (param instanceof ParametersWithRandom) {
        ParametersWithRandom rParam = (ParametersWithRandom) param;
        key = (RSAKeyParameters) rParam.getParameters();
        random = rParam.getRandom();
    } else {
        key = (RSAKeyParameters) param;
        random = new SecureRandom();
    }
}
Also used : ParametersWithRandom(org.bouncycastle.crypto.params.ParametersWithRandom) SecureRandom(java.security.SecureRandom)

Example 5 with ParametersWithRandom

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

the class DSASigner method init.

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

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