Search in sources :

Example 16 with InvalidParameterSpecException

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

the class DSAParameterGenerator method engineGenerateParameters.

/**
     * Generates the parameters.
     *
     * @return the new AlgorithmParameters object
     */
protected AlgorithmParameters engineGenerateParameters() {
    AlgorithmParameters algParams = null;
    try {
        if (this.random == null) {
            this.random = new SecureRandom();
        }
        if (valueL == -1) {
            try {
                engineInit(DEFAULTS, this.random);
            } catch (InvalidAlgorithmParameterException iape) {
            // should never happen
            }
        }
        BigInteger[] pAndQ = generatePandQ(this.random, valueL, valueN, seedLen);
        BigInteger paramP = pAndQ[0];
        BigInteger paramQ = pAndQ[1];
        BigInteger paramG = generateG(paramP, paramQ);
        DSAParameterSpec dsaParamSpec = new DSAParameterSpec(paramP, paramQ, paramG);
        algParams = AlgorithmParameters.getInstance("DSA", "SUN");
        algParams.init(dsaParamSpec);
    } catch (InvalidParameterSpecException e) {
        // this should never happen
        throw new RuntimeException(e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        // this should never happen, because we provide it
        throw new RuntimeException(e.getMessage());
    } catch (NoSuchProviderException e) {
        // this should never happen, because we provide it
        throw new RuntimeException(e.getMessage());
    }
    return algParams;
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecureRandom(java.security.SecureRandom) BigInteger(java.math.BigInteger) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 17 with InvalidParameterSpecException

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

the class DSAPrivateKey method getParams.

/**
     * Returns the DSA parameters associated with this key, or null if the
     * parameters could not be parsed.
     */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams) algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams) paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) DSAParams(java.security.interfaces.DSAParams) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 18 with InvalidParameterSpecException

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

the class DSAPublicKey method getParams.

/**
     * Returns the DSA parameters associated with this key, or null if the
     * parameters could not be parsed.
     */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams) algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams) paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) DSAParams(java.security.interfaces.DSAParams) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 19 with InvalidParameterSpecException

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

the class RC2Parameters method engineInit.

protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;
    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " + "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
Also used : RC2ParameterSpec(javax.crypto.spec.RC2ParameterSpec) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException)

Example 20 with InvalidParameterSpecException

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

the class AlgorithmParameters method init.

/**
     * Initializes this parameter object using the parameters
     * specified in {@code paramSpec}.
     *
     * @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)

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