Search in sources :

Example 41 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project jdk8u_jdk by JetBrains.

the class GCMParameters method engineInit.

protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
    if (!(paramSpec instanceof GCMParameterSpec)) {
        throw new InvalidParameterSpecException("Inappropriate parameter specification");
    }
    GCMParameterSpec gps = (GCMParameterSpec) paramSpec;
    // need to convert from bits to bytes for ASN.1 encoding
    this.tLen = gps.getTLen() / 8;
    this.iv = gps.getIV();
}
Also used : GCMParameterSpec(javax.crypto.spec.GCMParameterSpec) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException)

Example 42 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project android_frameworks_base by crdroidandroid.

the class AndroidKeyStoreUnauthenticatedAESCipherSpi method engineGetParameters.

@Nullable
@Override
protected final AlgorithmParameters engineGetParameters() {
    if (!mIvRequired) {
        return null;
    }
    if ((mIv != null) && (mIv.length > 0)) {
        try {
            AlgorithmParameters params = AlgorithmParameters.getInstance("AES");
            params.init(new IvParameterSpec(mIv));
            return params;
        } catch (NoSuchAlgorithmException e) {
            throw new ProviderException("Failed to obtain AES AlgorithmParameters", e);
        } catch (InvalidParameterSpecException e) {
            throw new ProviderException("Failed to initialize AES AlgorithmParameters with an IV", e);
        }
    }
    return null;
}
Also used : ProviderException(java.security.ProviderException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) AlgorithmParameters(java.security.AlgorithmParameters) Nullable(android.annotation.Nullable)

Example 43 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project android_frameworks_base by crdroidandroid.

the class AndroidKeyStoreUnauthenticatedAESCipherSpi method initAlgorithmSpecificParameters.

@Override
protected final void initAlgorithmSpecificParameters(AlgorithmParameters params) throws InvalidAlgorithmParameterException {
    if (!mIvRequired) {
        if (params != null) {
            throw new InvalidAlgorithmParameterException("Unsupported parameters: " + params);
        }
        return;
    }
    // IV is used
    if (params == null) {
        if (!isEncrypting()) {
            // IV must be provided by the caller
            throw new InvalidAlgorithmParameterException("IV required when decrypting" + ". Use IvParameterSpec or AlgorithmParameters to provide it.");
        }
        return;
    }
    if (!"AES".equalsIgnoreCase(params.getAlgorithm())) {
        throw new InvalidAlgorithmParameterException("Unsupported AlgorithmParameters algorithm: " + params.getAlgorithm() + ". Supported: AES");
    }
    IvParameterSpec ivSpec;
    try {
        ivSpec = params.getParameterSpec(IvParameterSpec.class);
    } catch (InvalidParameterSpecException e) {
        if (!isEncrypting()) {
            // IV must be provided by the caller
            throw new InvalidAlgorithmParameterException("IV required when decrypting" + ", but not found in parameters: " + params, e);
        }
        mIv = null;
        return;
    }
    mIv = ivSpec.getIV();
    if (mIv == null) {
        throw new InvalidAlgorithmParameterException("Null IV in AlgorithmParameters");
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException)

Example 44 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project Bytecoder by mirkosertic.

the class OAEPParameters method engineInit.

protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
    if (!(paramSpec instanceof OAEPParameterSpec)) {
        throw new InvalidParameterSpecException("Inappropriate parameter specification");
    }
    OAEPParameterSpec spec = (OAEPParameterSpec) paramSpec;
    mdName = spec.getDigestAlgorithm();
    String mgfName = spec.getMGFAlgorithm();
    if (!mgfName.equalsIgnoreCase("MGF1")) {
        throw new InvalidParameterSpecException("Unsupported mgf " + mgfName + "; MGF1 only");
    }
    AlgorithmParameterSpec mgfSpec = spec.getMGFParameters();
    if (!(mgfSpec instanceof MGF1ParameterSpec)) {
        throw new InvalidParameterSpecException("Inappropriate mgf " + "parameters; non-null MGF1ParameterSpec only");
    }
    this.mgfSpec = (MGF1ParameterSpec) mgfSpec;
    PSource pSrc = spec.getPSource();
    if (pSrc.getAlgorithm().equals("PSpecified")) {
        p = ((PSource.PSpecified) pSrc).getValue();
    } else {
        throw new InvalidParameterSpecException("Unsupported pSource " + pSrc.getAlgorithm() + "; PSpecified only");
    }
}
Also used : InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) PSource(javax.crypto.spec.PSource) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec) MGF1ParameterSpec(java.security.spec.MGF1ParameterSpec)

Example 45 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project Bytecoder by mirkosertic.

the class RSACipher method engineInit.

// see JCE spec
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params == null) {
        init(opmode, key, random, null);
    } else {
        try {
            OAEPParameterSpec spec = params.getParameterSpec(OAEPParameterSpec.class);
            init(opmode, key, random, spec);
        } catch (InvalidParameterSpecException ipse) {
            InvalidAlgorithmParameterException iape = new InvalidAlgorithmParameterException("Wrong parameter");
            iape.initCause(ipse);
            throw iape;
        }
    }
}
Also used : InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec)

Aggregations

InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)54 AlgorithmParameters (java.security.AlgorithmParameters)19 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)15 IvParameterSpec (javax.crypto.spec.IvParameterSpec)14 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)11 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)11 InvalidKeyException (java.security.InvalidKeyException)6 DSAParameterSpec (java.security.spec.DSAParameterSpec)6 OAEPParameterSpec (javax.crypto.spec.OAEPParameterSpec)6 Nullable (android.annotation.Nullable)5 ProviderException (java.security.ProviderException)5 DSAParams (java.security.interfaces.DSAParams)4 BadPaddingException (javax.crypto.BadPaddingException)4 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)4 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)4 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 BigInteger (java.math.BigInteger)3 NoSuchProviderException (java.security.NoSuchProviderException)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3