use of org.jcryptool.crypto.keystore.backend.KeyStoreAlias in project core by jcryptool.
the class AbstractKeyStoreHandler method addSecretKeyStatic.
public static KeyStoreAlias addSecretKeyStatic(INewEntryDescriptor descriptor, SecretKey key) {
// $NON-NLS-1$
LogUtil.logInfo("adding SecretKey");
KeyStoreAlias alias = new KeyStoreAlias(descriptor.getContactName(), KeyType.SECRETKEY, // key.getAlgorithm(),
descriptor.getDisplayedName(), (key.getEncoded().length * 8), ByteArrayUtils.toHexString(getHashValue(descriptor)), key.getClass().getName());
KeyStoreManager.getInstance().addSecretKey(key, descriptor.getPassword().toCharArray(), alias);
return alias;
}
use of org.jcryptool.crypto.keystore.backend.KeyStoreAlias in project core by jcryptool.
the class IntegratorWizardPage method makeNewKey.
protected void makeNewKey() {
Job[] preJobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
int preJobCount = preJobs.length;
KeyStoreHelper.makeSymmetricKeyByWizard(showKeyGroup).addObserver(new Observer() {
public void update(Observable o, final Object arg) {
if (arg != null) {
keyFromKeystoreGroup.getDisplay().syncExec(new Runnable() {
public void run() {
KeyStoreAlias ref = (KeyStoreAlias) arg;
setKeyForShowcase(ref);
}
});
}
}
});
Job[] jobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
if (jobs.length > preJobCount) {
createNewKeyButton.getDisplay().syncExec(new Runnable() {
public void run() {
buttonTextBeforeJobrunningMsg = createNewKeyButton.getText();
// $NON-NLS-1$
createNewKeyButton.setText(Messages.getString("IntegratorWizardPage.generatingButtonHint"));
disableControls();
}
});
Job job = jobs[jobs.length - 1];
IJobChangeListener listener = new IJobChangeListener() {
public void sleeping(IJobChangeEvent event) {
}
public void done(IJobChangeEvent event) {
createNewKeyButton.getDisplay().syncExec(new Runnable() {
public void run() {
createNewKeyButton.setText(buttonTextBeforeJobrunningMsg);
enableControls();
}
});
}
public void awake(IJobChangeEvent event) {
}
public void aboutToRun(IJobChangeEvent event) {
}
public void running(IJobChangeEvent event) {
}
public void scheduled(IJobChangeEvent event) {
}
};
if (job.getState() != Job.NONE)
job.addJobChangeListener(listener);
else {
listener.done(null);
}
}
}
use of org.jcryptool.crypto.keystore.backend.KeyStoreAlias in project core by jcryptool.
the class IntegratorWizardPage method refreshKeysFromKeystore.
private void refreshKeysFromKeystore(KeyStoreAlias previousSelection) {
publicKeyMap.clear();
privateKeyMap.clear();
comboKeyMap.clear();
try {
Enumeration<String> aliases = KeyStoreManager.getInstance().getAliases();
KeyStoreAlias localKeyStoreAlias = null;
while (aliases.hasMoreElements()) {
localKeyStoreAlias = new KeyStoreAlias(aliases.nextElement());
// String op = localKeyStoreAlias.getOperation();
if (localKeyStoreAlias.isOperationMatchingKeyId(showKeyGroup)) {
// $NON-NLS-1$
if (localKeyStoreAlias.getKeyStoreEntryType().getType().contains(KeyType.KEYPAIR.getType())) {
// asymmetric
if (localKeyStoreAlias.getKeyStoreEntryType().equals(KeyType.KEYPAIR_PUBLIC_KEY)) {
publicKeyMap.add(localKeyStoreAlias);
}
if (localKeyStoreAlias.getKeyStoreEntryType().equals(KeyType.KEYPAIR_PRIVATE_KEY)) {
privateKeyMap.add(localKeyStoreAlias);
}
} else {
// symmetric
publicKeyMap.add(localKeyStoreAlias);
privateKeyMap.add(localKeyStoreAlias);
}
}
}
} catch (Exception e) {
LogUtil.logError(e);
}
// if (publicKeyMap.isEmpty() || privateKeyMap.isEmpty()) {
// if(keyFromKeystoreButton != null) keyFromKeystoreButton.setEnabled(false);
// this.setErrorMessage(Messages.getString("DummyWizardPage.23") + " " + showKeyGroup + " " + Messages.getString("DummyWizardPage.232")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
// }
selectCurrentKey(previousSelection);
}
use of org.jcryptool.crypto.keystore.backend.KeyStoreAlias in project core by jcryptool.
the class IntegratorWizardPage method makeNewKeypair.
protected void makeNewKeypair() {
Job[] preJobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
int preJobCount = preJobs.length;
KeyStoreHelper.makeKeyPairByWizard(showKeyGroup).addObserver(new Observer() {
public void update(Observable o, final Object arg) {
if (arg != null) {
keyFromKeystoreGroup.getDisplay().syncExec(new Runnable() {
public void run() {
KeyStoreAlias ref = (KeyStoreAlias) arg;
setKeyForShowcase(ref);
}
});
}
}
});
Job[] jobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
if (jobs.length > preJobCount) {
createNewKeyButton.getDisplay().syncExec(new Runnable() {
public void run() {
buttonTextBeforeJobrunningMsg = createNewKeyButton.getText();
// $NON-NLS-1$
createNewKeyButton.setText(Messages.getString("IntegratorWizardPage.generatingButtonHint"));
disableControls();
}
});
Job job = jobs[jobs.length - 1];
IJobChangeListener listener = new IJobChangeListener() {
public void sleeping(IJobChangeEvent event) {
}
public void done(IJobChangeEvent event) {
createNewKeyButton.getDisplay().syncExec(new Runnable() {
public void run() {
createNewKeyButton.setText(buttonTextBeforeJobrunningMsg);
enableControls();
}
});
}
public void awake(IJobChangeEvent event) {
}
public void aboutToRun(IJobChangeEvent event) {
}
public void running(IJobChangeEvent event) {
}
public void scheduled(IJobChangeEvent event) {
}
};
if (job.getState() != Job.NONE)
job.addJobChangeListener(listener);
else {
listener.done(null);
}
}
}
use of org.jcryptool.crypto.keystore.backend.KeyStoreAlias in project core by jcryptool.
the class IntegratorWizardPage method selectCurrentKey.
/**
* selects current key in the key combo according to previousSelection
*
* @param previousSelection
*/
private void selectCurrentKey(KeyStoreAlias previousSelection) {
comboKeyMap.addAll(encrypt ? publicKeyMap : privateKeyMap);
keyCombo.setItems(getKeyItems());
if (keyCombo.getItemCount() == 0) {
// $NON-NLS-1$
keyCombo.add(Messages.getString("IntegratorWizardPage.noKeyFound"));
keyCombo.select(0);
keyCombo.setEnabled(false);
keyStoreAlias = null;
} else {
keyCombo.setEnabled(true);
if (previousSelection == null) {
keyCombo.select(0);
} else {
if (comboKeyMap.contains(previousSelection)) {
keyCombo.select(comboKeyMap.indexOf(previousSelection));
} else {
keyCombo.select(0);
String prevHash = previousSelection.getHashValue();
for (KeyStoreAlias alias : comboKeyMap) {
if (alias.getHashValue().equals(prevHash)) {
keyCombo.select(comboKeyMap.indexOf(alias));
break;
}
}
}
}
keyStoreAlias = comboKeyMap.get(keyCombo.getSelectionIndex());
}
}
Aggregations