Search in sources :

Example 6 with AsymmetricKeyParameter

use of org.bouncycastle.crypto.params.AsymmetricKeyParameter 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 7 with AsymmetricKeyParameter

use of org.bouncycastle.crypto.params.AsymmetricKeyParameter 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 8 with AsymmetricKeyParameter

use of org.bouncycastle.crypto.params.AsymmetricKeyParameter in project 360-Engine-for-Android by 360.

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 9 with AsymmetricKeyParameter

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

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)

Aggregations

AsymmetricKeyParameter (org.bouncycastle.crypto.params.AsymmetricKeyParameter)9 ParametersWithRandom (org.bouncycastle.crypto.params.ParametersWithRandom)7 SecureRandom (java.security.SecureRandom)4 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 Date (java.util.Date)2 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)2 X509CertificateHolder (org.bouncycastle.cert.X509CertificateHolder)2 DHPrivateKeyParameters (org.bouncycastle.crypto.params.DHPrivateKeyParameters)2 ContentSigner (org.bouncycastle.operator.ContentSigner)2 DefaultDigestAlgorithmIdentifierFinder (org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder)2 DefaultSignatureAlgorithmIdentifierFinder (org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder)2 BcRSAContentSignerBuilder (org.bouncycastle.operator.bc.BcRSAContentSignerBuilder)2 EOFException (java.io.EOFException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1 X500Name (org.bouncycastle.asn1.x500.X500Name)1 Certificate (org.bouncycastle.asn1.x509.Certificate)1