Search in sources :

Example 16 with NoSuchAlgorithmException

use of de.flexiprovider.api.exceptions.NoSuchAlgorithmException in project core by jcryptool.

the class CipherEngine method init.

@Override
public KeyObject init(IFlexiProviderOperation operation) {
    // $NON-NLS-1$
    LogUtil.logInfo("initializing cipher engine");
    this.operation = operation;
    char[] password = null;
    Key key = null;
    // password may be contained in the ActionItem, otherwise prompt
    if (operation.getPassword() != null) {
        password = operation.getPassword();
    } else {
        password = promptPassword();
    }
    if (password != null) {
        try {
            key = (Key) KeyStoreManager.getInstance().getSecretKey(operation.getKeyStoreAlias(), password);
            // save in the operation if no exception occurred
            operation.setPassword(password);
        } catch (UnrecoverableEntryException e) {
            JCTMessageDialog.showInfoDialog(new Status(IStatus.INFO, FlexiProviderEnginesPlugin.PLUGIN_ID, Messages.ExAccessKeystorePassword, e));
            return null;
        } catch (Exception e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "Exception while accessing a secret key", e, // $NON-NLS-1$
            true);
            return null;
        }
    }
    if (key != null) {
        try {
            cipher = Registry.getCipher(operation.getAlgorithmDescriptor().getAlgorithmName());
            if (operation.getOperation().equals(OperationType.ENCRYPT)) {
                cipher.initEncrypt(key, operation.getAlgorithmDescriptor().getAlgorithmParameterSpec(), FlexiProviderEnginesPlugin.getSecureRandom());
            } else {
                cipher.initDecrypt(key, operation.getAlgorithmDescriptor().getAlgorithmParameterSpec());
            }
            initialized = true;
        } catch (NoSuchAlgorithmException e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "NoSuchAlgorithmException while initializing a cipher engine", e, // $NON-NLS-1$
            true);
            return null;
        } catch (InvalidKeyException e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, Messages.CipherEngine_2, e, true);
            return null;
        } catch (InvalidAlgorithmParameterException e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "InvalidAlgorithmParameterException while initializing a cipher engine", e, // $NON-NLS-1$
            true);
            return null;
        }
    }
    return new KeyObject(key, password);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) InvalidKeyException(de.flexiprovider.api.exceptions.InvalidKeyException) Key(de.flexiprovider.api.keys.Key) BadPaddingException(de.flexiprovider.api.exceptions.BadPaddingException) IllegalBlockSizeException(de.flexiprovider.api.exceptions.IllegalBlockSizeException) PartInitException(org.eclipse.ui.PartInitException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) IOException(java.io.IOException) InvalidKeyException(de.flexiprovider.api.exceptions.InvalidKeyException) InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException)

Example 17 with NoSuchAlgorithmException

use of de.flexiprovider.api.exceptions.NoSuchAlgorithmException in project core by jcryptool.

the class AbstractKeyNodeContentProvider method getKeySpec.

protected KeySpec getKeySpec(Key key) {
    try {
        KeyFactory keyFactory = Registry.getKeyFactory(key.getAlgorithm());
        KeySpec keySpec = keyFactory.getKeySpec(key, AlgorithmParameterSpec.class);
        return keySpec;
    } catch (NoSuchAlgorithmException e) {
        return null;
    } catch (InvalidKeySpecException e) {
        return null;
    }
}
Also used : KeySpec(de.flexiprovider.api.keys.KeySpec) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) InvalidKeySpecException(de.flexiprovider.api.exceptions.InvalidKeySpecException) KeyFactory(de.flexiprovider.api.keys.KeyFactory)

Example 18 with NoSuchAlgorithmException

use of de.flexiprovider.api.exceptions.NoSuchAlgorithmException in project core by jcryptool.

the class ModeParameterSpecElement method getModeParameterSpec.

private ModeParameterSpec getModeParameterSpec(String encoded) {
    if (encoded != null) {
        // $NON-NLS-1$
        LogUtil.logInfo("getModeParameterSpec");
        try {
            byte[] encodedParams = Base64Coder.decode(encoded);
            // $NON-NLS-1$
            AlgorithmParameters params = Registry.getAlgParams("Mode");
            params.init(encodedParams);
            return (ModeParameterSpec) params.getParameterSpec(ModeParameterSpec.class);
        } catch (IOException e) {
            LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "IOException while decoding ModeParameters", e, false);
        } catch (NoSuchAlgorithmException e) {
            LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "NoSuchAlgorithmException while decoding ModeParameters", e, true);
        } catch (InvalidParameterSpecException e) {
            LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "InvalidParameterSpecException while decoding ModeParameters", e, true);
        }
    }
    return null;
}
Also used : IOException(java.io.IOException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) InvalidParameterSpecException(de.flexiprovider.api.exceptions.InvalidParameterSpecException) AlgorithmParameters(de.flexiprovider.api.parameters.AlgorithmParameters) ModeParameterSpec(de.flexiprovider.common.mode.ModeParameterSpec)

Example 19 with NoSuchAlgorithmException

use of de.flexiprovider.api.exceptions.NoSuchAlgorithmException 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 20 with NoSuchAlgorithmException

use of de.flexiprovider.api.exceptions.NoSuchAlgorithmException 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

NoSuchAlgorithmException (de.flexiprovider.api.exceptions.NoSuchAlgorithmException)20 InvalidAlgorithmParameterException (de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException)13 IOException (java.io.IOException)9 InvalidKeyException (de.flexiprovider.api.exceptions.InvalidKeyException)8 AlgorithmParameterSpec (de.flexiprovider.api.parameters.AlgorithmParameterSpec)8 Key (de.flexiprovider.api.keys.Key)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 UnrecoverableEntryException (java.security.UnrecoverableEntryException)6 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 WizardDialog (org.eclipse.jface.wizard.WizardDialog)5 IMetaKeyGenerator (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaKeyGenerator)5 InvalidParameterSpecException (de.flexiprovider.api.exceptions.InvalidParameterSpecException)4 AlgorithmParameters (de.flexiprovider.api.parameters.AlgorithmParameters)4 Wizard (org.eclipse.jface.wizard.Wizard)4 IMetaLength (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaLength)4 INewEntryDescriptor (org.jcryptool.crypto.keystore.descriptors.interfaces.INewEntryDescriptor)4 INewKeyWizard (org.jcryptool.crypto.keystore.descriptors.interfaces.INewKeyWizard)4 PrivateKey (de.flexiprovider.api.keys.PrivateKey)3 PublicKey (de.flexiprovider.api.keys.PublicKey)3