Search in sources :

Example 11 with NoSuchAlgorithmException

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

the class IntegratorHandler method execute.

/**
 * runs the action: setup the algorithm and executed the specified operation
 */
@Override
public Object execute(ExecutionEvent event) {
    AlgorithmDescriptor descriptor = getAlgorithmDescriptor(FLEXIPROVIDER_ALGORITHM_NAME);
    if (descriptor == null) {
        MessageBox messageBox = new MessageBox(getActiveWorkbenchWindow().getShell());
        // $NON-NLS-1$
        messageBox.setText(Messages.getString("DummyAction.error"));
        // $NON-NLS-1$
        messageBox.setMessage(Messages.getString("DummyAction.8"));
        messageBox.open();
        return (null);
    }
    String readableNameExtension;
    switch(algorithmType) {
        case TYPE_RANDOM_NUMBER_GENERATOR:
            // $NON-NLS-1$
            readableNameExtension = Messages.getString("DummyAction.random_number_generator");
            break;
        case TYPE_SIGNATURE:
            // $NON-NLS-1$
            readableNameExtension = Messages.getString("DummyAction.signature");
            break;
        case TYPE_MESSAGE_DIGEST:
            // $NON-NLS-1$
            readableNameExtension = Messages.getString("DummyAction.message_digest");
            break;
        case TYPE_MESSAGE_AUTHTIFICATION_CODE:
            // $NON-NLS-1$
            readableNameExtension = Messages.getString("DummyAction.message_authentification_code");
            break;
        default:
            // $NON-NLS-1$
            readableNameExtension = Messages.getString("DummyAction.encryption");
    }
    // Get which key lengths are valid for this algorithm
    int[] validKeyLengths = null;
    IMetaKeyGenerator keyGen = AlgorithmsXMLManager.getInstance().getSecretKeyGenerator(FLEXIPROVIDER_ALGORITHM_NAME);
    if (keyGen != null) {
        if (keyGen.getLengths().getLengths() != null) {
            validKeyLengths = new int[keyGen.getLengths().getLengths().size()];
            for (int i = 0; i < validKeyLengths.length; i++) validKeyLengths[i] = keyGen.getLengths().getLengths().get(i);
        } else {
            validKeyLengths = new int[1];
            validKeyLengths[0] = keyGen.getLengths().getDefaultLength();
        }
    }
    wizard = new IntegratorWizard(READABLE_ALGORITHM_NAME + readableNameExtension, READABLE_ALGORITHM_NAME, HEADER_DESCRIPTION, SHOW_OPERATION_GROUP, SHOW_PADDING_GROUP, SHOW_KEY, SHOW_KEY_SOURCE_GROUP, validKeyLengths, SHOW_SIGNATURE_GROUP, SHOW_RANDOM_GROUP, SHOW_MESSAGE_DIGEST_GROUP, algorithmType);
    WizardDialog dialog = new WizardDialog(getActiveWorkbenchWindow().getShell(), wizard);
    dialog.setHelpAvailable(true);
    switch(dialog.open()) {
        case Window.OK:
            if (algorithmType == TYPE_CIPHER_BLOCK) {
                descriptor = new BlockCipherDescriptor(descriptor.getAlgorithmName(), AlgorithmsXMLManager.getInstance().getMode(wizard.getMode().getDescription()).getID(), AlgorithmsXMLManager.getInstance().getPaddingScheme(wizard.getPadding().getPaddingSchemeName()).getID(), null, descriptor.getAlgorithmParameterSpec());
            }
            if (algorithmType == TYPE_RANDOM_NUMBER_GENERATOR) {
                if (wizard.doFilter())
                    descriptor = new SecureRandomDescriptor(descriptor.getAlgorithmName(), wizard.getRandomSize(), wizard.getFilter());
                else
                    descriptor = new SecureRandomDescriptor(descriptor.getAlgorithmName(), wizard.getRandomSize());
            }
            IntegratorOperation operation = new IntegratorOperation(descriptor);
            // $NON-NLS-1$
            operation.setEntryName("");
            // $NON-NLS-1$
            operation.setInput(Messages.getString("InputType"));
            // $NON-NLS-1$
            operation.setOutput("<Editor>");
            operation.setSignature(wizard.signature());
            operation.setUseCustomKey(wizard.useCustomKey());
            if (wizard.useCustomKey())
                operation.setKeyBytes(wizard.getCustomKey());
            try {
                if (// $NON-NLS-1$
                SHOW_KEY != null && !SHOW_KEY.equals("") && !wizard.useCustomKey())
                    operation.setKeyStoreAlias(wizard.getKey());
                if (wizard.encrypt()) {
                    // explicit encrypt
                    if (descriptor.getType() == RegistryType.SIGNATURE) {
                        operation.setOperation(OperationType.VERIFY);
                    } else {
                        operation.setOperation(OperationType.ENCRYPT);
                    }
                } else {
                    // implicit decrypt
                    if (descriptor.getType() == RegistryType.SIGNATURE) {
                        operation.setOperation(OperationType.SIGN);
                    } else {
                        operation.setOperation(OperationType.DECRYPT);
                    }
                }
                if (SHOW_MESSAGE_DIGEST_GROUP > 0 && !wizard.encrypt()) {
                    try {
                        MessageDigest digest = Registry.getMessageDigest(operation.getAlgorithmDescriptor().getAlgorithmName());
                        InputStream inputStream = EditorsManager.getInstance().getActiveEditorContentInputStream();
                        int i;
                        while ((i = inputStream.read()) != -1) {
                            digest.update((byte) i);
                        }
                        byte[] checksumAsBytes = digest.digest();
                        // $NON-NLS-1$
                        String checksum = "";
                        for (byte b : checksumAsBytes) {
                            String temp = Integer.toHexString((int) b);
                            // $NON-NLS-1$ //$NON-NLS-2$
                            checksum += (temp.length() == 1 ? "0" : "") + temp.substring(Math.max(0, temp.length() - 2));
                        }
                        String expectedChecksum = wizard.getExpectedChecksum();
                        if (checksum.equalsIgnoreCase(expectedChecksum)) {
                            MessageBox messageBox = new MessageBox(getActiveWorkbenchWindow().getShell(), SWT.ICON_WORKING);
                            // $NON-NLS-1$
                            messageBox.setText(Messages.getString("IntegratorAction.0"));
                            // $NON-NLS-1$
                            messageBox.setMessage(Messages.getString("IntegratorAction.1"));
                            messageBox.open();
                        } else {
                            MessageBox messageBox = new MessageBox(getActiveWorkbenchWindow().getShell(), SWT.ICON_ERROR);
                            // $NON-NLS-1$
                            messageBox.setText(Messages.getString("IntegratorAction.2"));
                            messageBox.setMessage(// $NON-NLS-1$
                            NLS.bind(// $NON-NLS-1$
                            Messages.getString("IntegratorAction.3"), new Object[] { checksum.toLowerCase(), expectedChecksum.toLowerCase() }));
                            messageBox.open();
                        }
                    } catch (NoSuchAlgorithmException e) {
                        LogUtil.logError(IntegratorPlugin.PLUGIN_ID, "NoSuchAlgorithmException while initializing a message digest", e, // $NON-NLS-1$
                        true);
                    }
                } else {
                    PerformOperationManager.getInstance().firePerformOperation(operation);
                }
                if (operation.getOperation() == OperationType.SIGN) {
                    MessageBox messageBox = new MessageBox(getActiveWorkbenchWindow().getShell(), SWT.NONE);
                    // $NON-NLS-1$
                    messageBox.setText(Messages.getString("DummyAction.13"));
                    // $NON-NLS-1$
                    messageBox.setMessage(Messages.getString("DummyAction.14") + wizard.signature());
                    messageBox.open();
                }
            } catch (IOException ex) {
                LogUtil.logError(ex);
            }
            break;
        case Window.CANCEL:
            break;
    }
    return (null);
}
Also used : InputStream(java.io.InputStream) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) IOException(java.io.IOException) IMetaKeyGenerator(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaKeyGenerator) AlgorithmDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor) MessageBox(org.eclipse.swt.widgets.MessageBox) SecureRandomDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.SecureRandomDescriptor) BlockCipherDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.BlockCipherDescriptor) IDataObject(org.jcryptool.core.operations.dataobject.IDataObject) MessageDigest(de.flexiprovider.api.MessageDigest) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 12 with NoSuchAlgorithmException

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

the class KeyStoreHelper method makeKeyPairByWizard.

public static KeyStoreAliasNotifier makeKeyPairByWizard(String keyType) {
    // $NON-NLS-1$
    LogUtil.logInfo("NewKeyPairAction");
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    Wizard wizard = new NewKeyPairWizard(keyType);
    WizardDialog dialog = new WizardDialog(shell, wizard);
    dialog.setMinimumPageSize(300, 350);
    final KeyStoreAliasNotifier resultAlias = new KeyStoreAliasNotifier();
    int result = dialog.open();
    if (result == Window.OK) {
        if (wizard instanceof INewKeyWizard) {
            final INewEntryDescriptor nkd = ((INewKeyWizard) wizard).getNewEntryDescriptor();
            final Integer[] argument = new Integer[1];
            final Integer arg = nkd.getKeyLength();
            argument[0] = arg;
            final Integer keyLen = argument[0];
            // $NON-NLS-1$
            LogUtil.logInfo("nkd.getKeyLength: " + argument[0]);
            Job job = new // $NON-NLS-1$
            Job(// $NON-NLS-1$
            "New Key Pair Job") {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    // $NON-NLS-1$
                    monitor.beginTask("New KeyPair Task", IProgressMonitor.UNKNOWN);
                    try {
                        IMetaKeyGenerator gen = AlgorithmsXMLManager.getInstance().getKeyPairGenerator(nkd.getAlgorithmName());
                        IMetaLength validKeyLengths = gen.getLengths();
                        // Check if entered key length is valid
                        boolean isValidKeyLength = true;
                        if (validKeyLengths != null) {
                            isValidKeyLength = (validKeyLengths.getDefaultLength() == keyLen) || (keyLen >= validKeyLengths.getLowerBound() && keyLen <= validKeyLengths.getUpperBound()) || (validKeyLengths.getLengths() != null && validKeyLengths.getLengths().contains(keyLen));
                        }
                        if (!isValidKeyLength) {
                            throw new InvalidAlgorithmParameterException("illegal key length");
                        }
                        AlgorithmParameterSpec spec = null;
                        if (arg != -1) {
                            if (gen.getParameterSpecClassName() != null) {
                                spec = Reflector.getInstance().instantiateParameterSpec(gen.getParameterSpecClassName(), argument);
                            }
                        }
                        KeyPairGenerator generator = Registry.getKeyPairGenerator(nkd.getAlgorithmName());
                        if (spec != null) {
                            generator.initialize(spec, FlexiProviderKeystorePlugin.getSecureRandom());
                        } else if (arg != -1) {
                            generator.initialize(arg, FlexiProviderKeystorePlugin.getSecureRandom());
                        }
                        KeyPair keyPair = generator.genKeyPair();
                        PrivateKey priv = keyPair.getPrivate();
                        PublicKey pub = keyPair.getPublic();
                        NewKeyPairDescriptor descriptor = new NewKeyPairDescriptor(nkd, priv, pub);
                        resultAlias.notifyAboutAlias(AbstractKeyStoreHandler.addKeyPairStatic(descriptor, ((NewKeyPairDescriptor) descriptor).getPrivateKey(), ((NewKeyPairDescriptor) descriptor).getPublicKey()));
                    } catch (NoSuchAlgorithmException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "NoSuchAlgorithmException while generating a key pair", e, true);
                    } catch (InvalidAlgorithmParameterException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "InvalidAlgorithmParameterException while generating a key pair", e, true);
                    } catch (SecurityException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "SecurityException while generating a key pair", e, true);
                    } catch (IllegalArgumentException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "IllegalArgumentException while generating a key pair", e, true);
                    } catch (ClassNotFoundException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "ClassNotFoundException while generating a key pair", e, true);
                    } catch (NoSuchMethodException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "NoSuchMethodException while generating a key pair", e, true);
                    } catch (InstantiationException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "InstantiationException while generating a key pair", e, true);
                    } catch (IllegalAccessException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "IllegalAccessException while generating a key pair", e, true);
                    } catch (InvocationTargetException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "InvocationTargetException while generating a key pair", e, true);
                    } finally {
                        monitor.done();
                    }
                    return Status.OK_STATUS;
                }

                @Override
                public boolean belongsTo(Object family) {
                    return family == KEYSTOREHELPER_FAMILY;
                }
            };
            job.setPriority(Job.LONG);
            job.setUser(true);
            job.schedule();
        }
    } else {
        resultAlias.notifyAboutAlias(null);
    }
    return resultAlias;
}
Also used : PrivateKey(de.flexiprovider.api.keys.PrivateKey) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) IMetaKeyGenerator(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaKeyGenerator) Shell(org.eclipse.swt.widgets.Shell) INewKeyWizard(org.jcryptool.crypto.keystore.descriptors.interfaces.INewKeyWizard) Job(org.eclipse.core.runtime.jobs.Job) NewKeyPairWizard(org.jcryptool.crypto.flexiprovider.keystore.wizards.NewKeyPairWizard) KeyPair(de.flexiprovider.api.keys.KeyPair) InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) PublicKey(de.flexiprovider.api.keys.PublicKey) KeyPairGenerator(de.flexiprovider.api.keys.KeyPairGenerator) InvocationTargetException(java.lang.reflect.InvocationTargetException) IMetaLength(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaLength) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NewKeyPairDescriptor(org.jcryptool.crypto.keystore.descriptors.NewKeyPairDescriptor) NewSymmetricKeyWizard(org.jcryptool.crypto.flexiprovider.keystore.wizards.NewSymmetricKeyWizard) Wizard(org.eclipse.jface.wizard.Wizard) INewKeyWizard(org.jcryptool.crypto.keystore.descriptors.interfaces.INewKeyWizard) NewKeyPairWizard(org.jcryptool.crypto.flexiprovider.keystore.wizards.NewKeyPairWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) AlgorithmParameterSpec(de.flexiprovider.api.parameters.AlgorithmParameterSpec) INewEntryDescriptor(org.jcryptool.crypto.keystore.descriptors.interfaces.INewEntryDescriptor)

Example 13 with NoSuchAlgorithmException

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

the class NewKeyPairHandler method execute.

/**
 * @see org.eclipse.jface.action.Action#run()
 */
public Object execute(ExecutionEvent event) {
    // $NON-NLS-1$
    LogUtil.logInfo("NewKeyPairAction");
    shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    Wizard wizard = new NewKeyPairWizard();
    dialog = new WizardDialog(shell, wizard);
    dialog.setMinimumPageSize(300, 350);
    int result = dialog.open();
    if (result == Window.OK) {
        if (wizard instanceof INewKeyWizard) {
            final INewEntryDescriptor nkd = ((INewKeyWizard) wizard).getNewEntryDescriptor();
            final Integer[] argument = new Integer[1];
            final Integer arg = nkd.getKeyLength();
            argument[0] = arg;
            final Integer keyLen = argument[0];
            // $NON-NLS-1$
            LogUtil.logInfo("nkd.getKeyLength: " + argument[0]);
            Job job = new Job(Messages.NewKeyPairHandler_2) {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    monitor.beginTask(Messages.NewKeyPairHandler_3, IProgressMonitor.UNKNOWN);
                    try {
                        IMetaKeyGenerator gen = AlgorithmsXMLManager.getInstance().getKeyPairGenerator(nkd.getAlgorithmName());
                        IMetaLength validKeyLengths = gen.getLengths();
                        // Check if entered key length is valid
                        boolean isValidKeyLength = true;
                        if (validKeyLengths != null) {
                            isValidKeyLength = (validKeyLengths.getDefaultLength() == keyLen) || (keyLen >= validKeyLengths.getLowerBound() && keyLen <= validKeyLengths.getUpperBound()) || (validKeyLengths.getLengths() != null && validKeyLengths.getLengths().contains(keyLen));
                        }
                        if (!isValidKeyLength) {
                            // $NON-NLS-1$
                            throw new InvalidAlgorithmParameterException("illegal key length");
                        }
                        AlgorithmParameterSpec spec = null;
                        if (arg != -1) {
                            if (gen.getParameterSpecClassName() != null) {
                                spec = Reflector.getInstance().instantiateParameterSpec(gen.getParameterSpecClassName(), argument);
                            }
                        }
                        KeyPairGenerator generator = Registry.getKeyPairGenerator(nkd.getAlgorithmName());
                        if (spec != null) {
                            generator.initialize(spec, FlexiProviderKeystorePlugin.getSecureRandom());
                        } else if (arg != -1) {
                            generator.initialize(arg, FlexiProviderKeystorePlugin.getSecureRandom());
                        }
                        KeyPair keyPair = generator.genKeyPair();
                        PrivateKey priv = keyPair.getPrivate();
                        PublicKey pub = keyPair.getPublic();
                        performNewKeyAction(new NewKeyPairDescriptor(nkd, priv, pub));
                    } catch (NoSuchAlgorithmException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "NoSuchAlgorithmException while generating a key pair", e, // $NON-NLS-1$
                        true);
                    } catch (InvalidAlgorithmParameterException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "InvalidAlgorithmParameterException while generating a key pair", e, // $NON-NLS-1$
                        true);
                    } catch (SecurityException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "SecurityException while generating a key pair", e, // $NON-NLS-1$
                        true);
                    } catch (IllegalArgumentException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "IllegalArgumentException while generating a key pair", e, // $NON-NLS-1$
                        true);
                    } catch (ClassNotFoundException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "ClassNotFoundException while generating a key pair", e, // $NON-NLS-1$
                        true);
                    } catch (NoSuchMethodException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "NoSuchMethodException while generating a key pair", e, // $NON-NLS-1$
                        true);
                    } catch (InstantiationException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "InstantiationException while generating a key pair", e, // $NON-NLS-1$
                        true);
                    } catch (IllegalAccessException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "IllegalAccessException while generating a key pair", e, // $NON-NLS-1$
                        true);
                    } catch (InvocationTargetException e) {
                        LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "InvocationTargetException while generating a key pair", e, // $NON-NLS-1$
                        true);
                    } finally {
                        monitor.done();
                    }
                    return Status.OK_STATUS;
                }
            };
            job.setPriority(Job.LONG);
            // job.setUser(true);
            job.schedule();
        }
    }
    return (null);
}
Also used : PrivateKey(de.flexiprovider.api.keys.PrivateKey) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) IMetaKeyGenerator(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaKeyGenerator) INewKeyWizard(org.jcryptool.crypto.keystore.descriptors.interfaces.INewKeyWizard) Job(org.eclipse.core.runtime.jobs.Job) NewKeyPairWizard(org.jcryptool.crypto.flexiprovider.keystore.wizards.NewKeyPairWizard) KeyPair(de.flexiprovider.api.keys.KeyPair) InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) PublicKey(de.flexiprovider.api.keys.PublicKey) KeyPairGenerator(de.flexiprovider.api.keys.KeyPairGenerator) InvocationTargetException(java.lang.reflect.InvocationTargetException) IMetaLength(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaLength) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NewKeyPairDescriptor(org.jcryptool.crypto.keystore.descriptors.NewKeyPairDescriptor) Wizard(org.eclipse.jface.wizard.Wizard) INewKeyWizard(org.jcryptool.crypto.keystore.descriptors.interfaces.INewKeyWizard) NewKeyPairWizard(org.jcryptool.crypto.flexiprovider.keystore.wizards.NewKeyPairWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) AlgorithmParameterSpec(de.flexiprovider.api.parameters.AlgorithmParameterSpec) INewEntryDescriptor(org.jcryptool.crypto.keystore.descriptors.interfaces.INewEntryDescriptor)

Example 14 with NoSuchAlgorithmException

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

the class NewSymmetricKeyHandler method execute.

/**
 * @see org.eclipse.jface.action.Action#run()
 */
public Object execute(ExecutionEvent event) {
    // $NON-NLS-1$
    LogUtil.logInfo("NewSymmetricKeyAction");
    shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    Wizard wizard = new NewSymmetricKeyWizard();
    dialog = new WizardDialog(shell, wizard);
    dialog.setMinimumPageSize(300, 350);
    int result = dialog.open();
    if (result == Window.OK) {
        if (wizard instanceof INewKeyWizard) {
            INewEntryDescriptor nkd = ((INewKeyWizard) wizard).getNewEntryDescriptor();
            Integer[] argument = new Integer[1];
            argument[0] = nkd.getKeyLength();
            Integer keyLen = argument[0];
            // $NON-NLS-1$
            LogUtil.logInfo("key strength: " + argument[0]);
            try {
                IMetaKeyGenerator gen = AlgorithmsXMLManager.getInstance().getSecretKeyGenerator(nkd.getAlgorithmName());
                IMetaLength validKeyLengths = gen.getLengths();
                // Check if entered key length is valid
                boolean isValidKeyLength = true;
                if (validKeyLengths != null) {
                    isValidKeyLength = (validKeyLengths.getDefaultLength() == keyLen) || (keyLen >= validKeyLengths.getLowerBound() && keyLen <= validKeyLengths.getUpperBound()) || (validKeyLengths.getLengths() != null && validKeyLengths.getLengths().contains(keyLen));
                }
                if (!isValidKeyLength) {
                    throw new InvalidAlgorithmParameterException("illegal key length");
                }
                AlgorithmParameterSpec spec = null;
                if (gen.getParameterSpecClassName() != null) {
                    spec = Reflector.getInstance().instantiateParameterSpec(gen.getParameterSpecClassName(), argument);
                }
                SecretKeyGenerator generator = Registry.getSecretKeyGenerator(nkd.getAlgorithmName());
                if (spec != null) {
                    // $NON-NLS-1$
                    LogUtil.logInfo("initializing generator with spec");
                    generator.init(spec, FlexiProviderKeystorePlugin.getSecureRandom());
                } else {
                    generator.init(FlexiProviderKeystorePlugin.getSecureRandom());
                }
                SecretKey key = generator.generateKey();
                performNewKeyAction(new NewSecretKeyDescriptor(nkd, key));
            } catch (SecurityException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "SecurityException while generating a secret key", e, true);
            } catch (IllegalArgumentException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "IllegalArgumentException while generating a secret key", e, true);
            } catch (ClassNotFoundException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "ClassNotFoundException while generating a secret key", e, true);
            } catch (NoSuchMethodException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "NoSuchMethodException while generating a secret key", e, true);
            } catch (InstantiationException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "InstantiationException while generating a secret key", e, true);
            } catch (IllegalAccessException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "IllegalAccessException while generating a secret key", e, true);
            } catch (InvocationTargetException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "InvocationTargetException while generating a secret key", e, true);
            } catch (NoSuchAlgorithmException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "NoSuchAlgorithmException while generating a secret key", e, true);
            } catch (InvalidAlgorithmParameterException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "InvalidAlgorithmParameterException while generating a secret key", e, true);
            }
        }
    }
    return (null);
}
Also used : NewSecretKeyDescriptor(org.jcryptool.crypto.keystore.descriptors.NewSecretKeyDescriptor) InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) IMetaKeyGenerator(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaKeyGenerator) InvocationTargetException(java.lang.reflect.InvocationTargetException) IMetaLength(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaLength) SecretKey(de.flexiprovider.api.keys.SecretKey) NewSymmetricKeyWizard(org.jcryptool.crypto.flexiprovider.keystore.wizards.NewSymmetricKeyWizard) SecretKeyGenerator(de.flexiprovider.api.keys.SecretKeyGenerator) INewKeyWizard(org.jcryptool.crypto.keystore.descriptors.interfaces.INewKeyWizard) NewSymmetricKeyWizard(org.jcryptool.crypto.flexiprovider.keystore.wizards.NewSymmetricKeyWizard) Wizard(org.eclipse.jface.wizard.Wizard) INewKeyWizard(org.jcryptool.crypto.keystore.descriptors.interfaces.INewKeyWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) AlgorithmParameterSpec(de.flexiprovider.api.parameters.AlgorithmParameterSpec) INewEntryDescriptor(org.jcryptool.crypto.keystore.descriptors.interfaces.INewEntryDescriptor)

Example 15 with NoSuchAlgorithmException

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

the class BlockCipherWizardDialog method nextPressed.

public void nextPressed() {
    // $NON-NLS-1$
    LogUtil.logInfo("next pressed");
    if (wizard.hasAlgorithmParameterSpecPage() && getCurrentPage().getName().equals("AlgorithmParameterWizardPage")) {
        // $NON-NLS-1$
        Object[] values = wizard.getAlgorithmParameterValues();
        for (Object value : values) {
            // $NON-NLS-1$ //$NON-NLS-2$
            LogUtil.logInfo("Value: " + value + " of type: " + value.getClass().getName());
        }
        try {
            dummyKey = wizard.getDummyKey();
            BlockCipher cipher = Registry.getBlockCipher(algorithm.getName());
            AlgorithmParameterSpec spec = Reflector.getInstance().instantiateParameterSpec(algorithm.getParameterSpecClassName(), values);
            cipher.initEncrypt(dummyKey, null, spec, FlexiProviderAlgorithmsPlugin.getSecureRandom());
            modeBlockSize = cipher.getBlockSize();
            wizard.setModeBlockSize(modeBlockSize);
        } catch (NoSuchAlgorithmException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "NoSuchAlgorithmException while initializing a block cipher", e, true);
        } catch (NoSuchPaddingException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "NoSuchPaddingException while initializing a block cipher", e, true);
        } catch (InvalidKeyException e) {
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, Messages.BlockCipherWizardDialog_2, e, true);
        } catch (InvalidAlgorithmParameterException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "InvalidAlgorithmParameterException while initializing a block cipher", e, true);
        } catch (SecurityException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "SecurityException while initializing a block cipher", e, true);
        } catch (IllegalArgumentException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "IllegalArgumentException while initializing a block cipher", e, true);
        } catch (ClassNotFoundException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "ClassNotFoundException while initializing a block cipher", e, true);
        } catch (NoSuchMethodException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "NoSuchMethodException while initializing a block cipher", e, true);
        } catch (InstantiationException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "InstantiationException while initializing a block cipher", e, true);
        } catch (IllegalAccessException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "IllegalAccessException while initializing a block cipher", e, true);
        } catch (InvocationTargetException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "InvocationTargetException while initializing a block cipher", e, true);
        }
    }
    super.nextPressed();
}
Also used : InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) BlockCipher(de.flexiprovider.api.BlockCipher) NoSuchPaddingException(de.flexiprovider.api.exceptions.NoSuchPaddingException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) InvalidKeyException(de.flexiprovider.api.exceptions.InvalidKeyException) InvocationTargetException(java.lang.reflect.InvocationTargetException) 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