use of de.flexiprovider.api.parameters.AlgorithmParameterSpec 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);
}
use of de.flexiprovider.api.parameters.AlgorithmParameterSpec 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();
}
use of de.flexiprovider.api.parameters.AlgorithmParameterSpec in project core by jcryptool.
the class AlgorithmsManager method performMessageDigestCalled.
private static void performMessageDigestCalled(IMetaAlgorithm algorithm) {
// $NON-NLS-1$
LogUtil.logInfo("has param generator: " + (algorithm.getParameterGeneratorClassName() != null));
if (algorithm.getParameterGeneratorClassName() != null && !algorithm.isParameterSpecDisabled()) {
AlgorithmParameterSpec generatedSpec = Reflector.getInstance().generateDefaultParameterSpec(algorithm);
NewOperationManager.getInstance().fireNewOperation(new AlgorithmDescriptor(algorithm.getName(), RegistryType.MESSAGE_DIGEST, generatedSpec));
} else {
NewOperationManager.getInstance().fireNewOperation(new AlgorithmDescriptor(algorithm.getName(), RegistryType.MESSAGE_DIGEST, null));
}
}
use of de.flexiprovider.api.parameters.AlgorithmParameterSpec in project core by jcryptool.
the class AlgorithmsManager method performMacCalled.
private static void performMacCalled(IMetaAlgorithm algorithm) {
if (algorithm.getBlockCipherName() != null) {
IMetaAlgorithm bc = null;
// $NON-NLS-1$
LogUtil.logInfo("BC name: " + algorithm.getBlockCipherName());
if (algorithm.getBlockCipherOID() != null) {
// $NON-NLS-1$
LogUtil.logInfo("BC oid: " + algorithm.getBlockCipherOID());
bc = AlgorithmsXMLManager.getInstance().getBlockCipher(algorithm.getBlockCipherOID());
} else {
bc = AlgorithmsXMLManager.getInstance().getBlockCipher(algorithm.getBlockCipherName());
}
// $NON-NLS-1$
LogUtil.logInfo("BC mode: " + algorithm.getBlockCipherMode());
if (bc != null) {
blockCipherWizard = new BlockCipherWizard(bc, algorithm.getBlockCipherMode());
dialog = new BlockCipherWizardDialog(shell, blockCipherWizard);
dialog.setMinimumPageSize(300, 175);
int result = dialog.open();
if (result == Window.OK) {
AlgorithmDescriptor blockCipherDescriptor = blockCipherWizard.getDescriptor();
AlgorithmDescriptor macDescriptor = new AlgorithmDescriptor(algorithm.getName(), RegistryType.MAC, blockCipherDescriptor.getAlgorithmParameterSpec());
NewOperationManager.getInstance().fireNewOperation(macDescriptor);
return;
}
}
}
if (algorithm.getParameterSpecClassName() != null && !algorithm.isParameterSpecDisabled()) {
algorithmWizard = new AlgorithmWizard(algorithm);
dialog = new WizardDialog(shell, algorithmWizard);
dialog.setMinimumPageSize(300, 100);
int result = dialog.open();
if (result == Window.OK) {
// $NON-NLS-1$
LogUtil.logInfo("adding mac");
NewOperationManager.getInstance().fireNewOperation(algorithmWizard.getDescriptor());
} else {
// $NON-NLS-1$
LogUtil.logInfo("adding mac w/o parameter spec");
// $NON-NLS-1$
LogUtil.logInfo("has param generator: " + (algorithm.getParameterGeneratorClassName() != null));
if (algorithm.getParameterGeneratorClassName() != null) {
AlgorithmParameterSpec generatedSpec = Reflector.getInstance().generateDefaultParameterSpec(algorithm);
NewOperationManager.getInstance().fireNewOperation(new AlgorithmDescriptor(algorithm.getName(), RegistryType.MAC, generatedSpec));
} else {
NewOperationManager.getInstance().fireNewOperation(new AlgorithmDescriptor(algorithm.getName(), RegistryType.MAC, null));
}
}
}
}
use of de.flexiprovider.api.parameters.AlgorithmParameterSpec 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;
}
Aggregations