Search in sources :

Example 31 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project j2objc by google.

the class AlgorithmParameters method init.

/**
     * Initializes this parameter object using the parameters
     * specified in <code>paramSpec</code>.
     *
     * @param paramSpec the parameter specification.
     *
     * @exception InvalidParameterSpecException if the given parameter
     * specification is inappropriate for the initialization of this parameter
     * object, or if this parameter object has already been initialized.
     */
public final void init(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
    if (this.initialized)
        throw new InvalidParameterSpecException("already initialized");
    paramSpi.engineInit(paramSpec);
    this.initialized = true;
}
Also used : InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException)

Example 32 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project platform_frameworks_base by android.

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 33 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project robovm by robovm.

the class InvalidParameterSpecExceptionTest method testInvalidParameterSpecException03.

/**
     * Test for <code>InvalidParameterSpecException(String)</code> constructor
     * Assertion: constructs InvalidParameterSpecException when <code>msg</code>
     * is null
     */
public void testInvalidParameterSpecException03() {
    String msg = null;
    InvalidParameterSpecException tE = new InvalidParameterSpecException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException)

Example 34 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project robovm by robovm.

the class InvalidParameterSpecExceptionTest method testInvalidParameterSpecException02.

/**
     * Test for <code>InvalidParameterSpecException(String)</code> constructor
     * Assertion: constructs InvalidParameterSpecException with detail message
     * msg. Parameter <code>msg</code> is not null.
     */
public void testInvalidParameterSpecException02() {
    InvalidParameterSpecException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new InvalidParameterSpecException(msgs[i]);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", tE.getCause());
    }
}
Also used : InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException)

Example 35 with InvalidParameterSpecException

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

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)

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