use of de.flexiprovider.api.keys.Key in project core by jcryptool.
the class SignatureEngine method init.
@Override
public KeyObject init(IFlexiProviderOperation operation) {
// $NON-NLS-1$
LogUtil.logInfo("initializing signature engine");
this.operation = operation;
char[] password = null;
KeyObject usedKey = null;
try {
signature = Registry.getSignature(operation.getAlgorithmDescriptor().getAlgorithmName());
AlgorithmParameterSpec spec = operation.getAlgorithmDescriptor().getAlgorithmParameterSpec();
if (spec != null) {
signature.setParameters(spec);
}
if (operation.getOperation().equals(OperationType.SIGN)) {
if (operation.getPassword() != null) {
password = operation.getPassword();
} else {
password = promptPassword();
}
if (password == null) {
return null;
}
Key privateKey = (Key) KeyStoreManager.getInstance().getPrivateKey(operation.getKeyStoreAlias(), password);
signature.initSign((PrivateKey) privateKey, FlexiProviderEnginesPlugin.getSecureRandom());
usedKey = new KeyObject(privateKey, password);
// save in the operation if no exception occurred
operation.setPassword(password);
} else {
Certificate certificate = KeyStoreManager.getInstance().getCertificate(operation.getKeyStoreAlias());
Key publicKey = (Key) certificate.getPublicKey();
signature.initVerify((PublicKey) publicKey);
usedKey = new KeyObject(publicKey, password);
}
initialized = true;
} catch (NoSuchAlgorithmException e) {
LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "NoSuchAlgorithmException while initializing a signature", e, // $NON-NLS-1$
true);
return null;
} catch (InvalidAlgorithmParameterException e) {
LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "InvalidAlgorithmParameterException while initializing a signature", e, // $NON-NLS-1$
true);
return null;
} catch (InvalidKeyException e) {
LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, Messages.SignatureEngine_5, e, true);
return null;
} catch (UnrecoverableEntryException e) {
JCTMessageDialog.showInfoDialog(new Status(IStatus.INFO, FlexiProviderEnginesPlugin.PLUGIN_ID, Messages.ExAccessKeystorePassword, e));
return null;
} catch (Exception e) {
// $NON-NLS-1$
LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "Exception while initializing a signature", e, true);
return null;
}
return usedKey;
}
use of de.flexiprovider.api.keys.Key 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);
}
use of de.flexiprovider.api.keys.Key in project core by jcryptool.
the class AbstractKeyNodeContentProvider method getElements.
@Override
public Object[] getElements(Object inputElement) {
Object[] elements = super.getElements(inputElement);
Key key = getKey(inputElement);
List<TableEntry> aliasElements = getAliasElements(inputElement);
List<TableEntry> keyElements = getKeyElements(key);
List<TableEntry> keySpecElements = getKeySpecElements(key);
List<TableEntry> cipherElements = getCipherElements(key);
List<TableEntry> algorithmElements = getAlgorithmElements(key);
List<Object> abstractKeyNodeElements = new ArrayList<Object>();
if (elements != null)
abstractKeyNodeElements.addAll(Arrays.asList(elements));
if (aliasElements != null)
abstractKeyNodeElements.addAll(aliasElements);
if (keyElements != null)
abstractKeyNodeElements.addAll(keyElements);
if (cipherElements != null)
abstractKeyNodeElements.addAll(cipherElements);
if (algorithmElements != null)
abstractKeyNodeElements.addAll(algorithmElements);
if (keySpecElements != null)
abstractKeyNodeElements.addAll(keySpecElements);
return abstractKeyNodeElements.toArray();
}
use of de.flexiprovider.api.keys.Key in project core by jcryptool.
the class AbstractKeyNodeContentProvider method getKeyElements.
private List<TableEntry> getKeyElements(Object inputElement) {
Key key = (Key) inputElement;
if (key == null)
return null;
List<TableEntry> list = new ArrayList<TableEntry>();
list.add(new TableEntry(Messages.AbstractKeyNodeContentProvider_Algorithm, key.getAlgorithm()));
list.add(new TableEntry(Messages.AbstractKeyNodeContentProvider_Format, key.getFormat()));
list.add(new TableEntry(Messages.AbstractKeyNodeContentProvider_Encoded, Arrays.toString(key.getEncoded())));
return list;
}
Aggregations