Search in sources :

Example 1 with AlgorithmParameterGenerator

use of de.flexiprovider.api.parameters.AlgorithmParameterGenerator in project core by jcryptool.

the class Reflector method generateParameterSpec.

public AlgorithmParameterSpec generateParameterSpec(final IMetaAlgorithm algorithm, final String specClassName, final Object[] parameters) {
    final List<String> names = algorithm.getNames();
    // $NON-NLS-1$
    String useName = "-1";
    for (final String name : names) {
        try {
            Registry.getAlgParamGenerator(name);
            useName = name;
            break;
        } catch (final NoSuchAlgorithmException e) {
        }
    }
    try {
        final AlgorithmParameterGenerator generator = Registry.getAlgParamGenerator(useName);
        generator.init(this.instantiateParameterSpec(specClassName, parameters), FlexiProviderPlugin.getSecureRandom());
        return generator.generateParameters();
    } catch (final NoSuchAlgorithmException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, e);
    } catch (final InvalidAlgorithmParameterException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, e);
    } catch (final SecurityException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, e);
    } catch (final IllegalArgumentException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, e);
    } catch (final ClassNotFoundException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, e);
    } catch (final NoSuchMethodException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, e);
    } catch (final InstantiationException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, e);
    } catch (final IllegalAccessException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, e);
    } catch (final InvocationTargetException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, e);
    }
    return null;
}
Also used : InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) AlgorithmParameterGenerator(de.flexiprovider.api.parameters.AlgorithmParameterGenerator) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with AlgorithmParameterGenerator

use of de.flexiprovider.api.parameters.AlgorithmParameterGenerator in project core by jcryptool.

the class Reflector method generateDefaultParameterSpec.

public AlgorithmParameterSpec generateDefaultParameterSpec(final IMetaAlgorithm algorithm) {
    final List<String> names = algorithm.getNames();
    // $NON-NLS-1$
    String useName = "-1";
    for (final String name : names) {
        try {
            Registry.getAlgParamGenerator(name);
            useName = name;
            break;
        } catch (final NoSuchAlgorithmException e) {
        }
    }
    try {
        final AlgorithmParameterGenerator generator = Registry.getAlgParamGenerator(useName);
        // $NON-NLS-1$
        final AlgorithmParameterSpec spec = Registry.getAlgParamSpec(useName + "ParamGen");
        generator.init(spec, FlexiProviderPlugin.getSecureRandom());
        return generator.generateParameters();
    } catch (final NoSuchAlgorithmException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, "NoSuchAlgorithmException while generating default parameters for " + algorithm.getName(), e, // $NON-NLS-1$
        true);
    } catch (final InvalidAlgorithmParameterException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, // $NON-NLS-1$
        "InvalidAlgorithmParameterException while generating default parameters for " + algorithm.getName(), e, true);
    }
    return null;
}
Also used : InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) AlgorithmParameterGenerator(de.flexiprovider.api.parameters.AlgorithmParameterGenerator) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) AlgorithmParameterSpec(de.flexiprovider.api.parameters.AlgorithmParameterSpec)

Aggregations

InvalidAlgorithmParameterException (de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException)2 NoSuchAlgorithmException (de.flexiprovider.api.exceptions.NoSuchAlgorithmException)2 AlgorithmParameterGenerator (de.flexiprovider.api.parameters.AlgorithmParameterGenerator)2 AlgorithmParameterSpec (de.flexiprovider.api.parameters.AlgorithmParameterSpec)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1