use of org.kse.crypto.secretkey.SecretKeyType in project keystore-explorer by kaikramer.
the class GenerateSecretKeyAction method generateSecret.
/**
* Generate a secret key in the currently opened KeyStore.
*/
public void generateSecret() {
try {
int secretKeySize = applicationSettings.getGenerateSecretKeySize();
SecretKeyType secretKeyType = applicationSettings.getGenerateSecretKeyType();
DGenerateSecretKey dGenerateSecretKey = new DGenerateSecretKey(frame, secretKeyType, secretKeySize);
dGenerateSecretKey.setLocationRelativeTo(frame);
dGenerateSecretKey.setVisible(true);
if (!dGenerateSecretKey.isSuccessful()) {
return;
}
secretKeySize = dGenerateSecretKey.getSecretKeySize();
secretKeyType = dGenerateSecretKey.getSecretKeyType();
applicationSettings.setGenerateSecretKeySize(secretKeySize);
applicationSettings.setGenerateSecretKeyType(secretKeyType);
SecretKey secretKey = SecretKeyUtil.generateSecretKey(secretKeyType, secretKeySize);
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStoreState newState = currentState.createBasisForNextState(this);
KeyStore keyStore = newState.getKeyStore();
DGetAlias dGetAlias = new DGetAlias(frame, res.getString("GenerateSecretKeyAction.NewSecretKeyEntryAlias.Title"), null);
dGetAlias.setLocationRelativeTo(frame);
dGetAlias.setVisible(true);
String alias = dGetAlias.getAlias();
if (alias == null) {
return;
}
if (keyStore.containsAlias(alias)) {
String message = MessageFormat.format(res.getString("GenerateSecretKeyAction.OverWriteEntry.message"), alias);
int selected = JOptionPane.showConfirmDialog(frame, message, res.getString("GenerateSecretKeyAction.NewSecretKeyEntryAlias.Title"), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return;
}
}
Password password = new Password((char[]) null);
KeyStoreType type = KeyStoreType.resolveJce(keyStore.getType());
if (type.hasEntryPasswords()) {
DGetNewPassword dGetNewPassword = new DGetNewPassword(frame, res.getString("GenerateSecretKeyAction.NewSecretKeyEntryPassword.Title"), applicationSettings.getPasswordQualityConfig());
dGetNewPassword.setLocationRelativeTo(frame);
dGetNewPassword.setVisible(true);
password = dGetNewPassword.getPassword();
if (password == null) {
return;
}
}
if (keyStore.containsAlias(alias)) {
keyStore.deleteEntry(alias);
newState.removeEntryPassword(alias);
}
keyStore.setKeyEntry(alias, secretKey, password.toCharArray(), null);
newState.setEntryPassword(alias, password);
currentState.append(newState);
kseFrame.updateControls(true);
JOptionPane.showMessageDialog(frame, res.getString("GenerateSecretKeyAction.SecretKeyGenerationSuccessful.message"), res.getString("GenerateSecretKeyAction.GenerateSecretKey.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.crypto.secretkey.SecretKeyType in project keystore-explorer by kaikramer.
the class DViewSecretKey method populateDialog.
private void populateDialog() throws CryptoException {
KeyInfo keyInfo = SecretKeyUtil.getKeyInfo(secretKey);
String algorithm = keyInfo.getAlgorithm();
// Try and get friendly algorithm name
SecretKeyType secretKeyType = SecretKeyType.resolveJce(algorithm);
if (secretKeyType != null) {
algorithm = secretKeyType.friendly();
}
jtfAlgorithm.setText(algorithm);
Integer keyLength = keyInfo.getSize();
if (keyLength != null) {
jtfKeySize.setText(MessageFormat.format(res.getString("DViewSecretKey.jtfKeySize.text"), "" + keyLength));
} else {
jtfKeySize.setText(MessageFormat.format(res.getString("DViewSecretKey.jtfKeySize.text"), "?"));
}
jtfFormat.setText(secretKey.getFormat());
jtfEncoded.setText("0x" + new BigInteger(1, secretKey.getEncoded()).toString(16).toUpperCase());
jtfEncoded.setCaretPosition(0);
}
use of org.kse.crypto.secretkey.SecretKeyType in project keystore-explorer by kaikramer.
the class DGenerateSecretKey method initComponents.
private void initComponents() {
jlKeySize = new JLabel(res.getString("DGenerateSecretKey.jlKeySize.text"));
jsKeySize = new JSpinner();
jsKeySize.setToolTipText(res.getString("DGenerateSecretKey.jsKeySize.tooltip"));
jpKeySize = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpKeySize.add(jlKeySize);
jpKeySize.add(jsKeySize);
jlKeyAlg = new JLabel(res.getString("DGenerateSecretKey.jlKeyAlg.text"));
jcbKeyAlg = new JComboBox<SecretKeyType>();
jcbKeyAlg.setToolTipText(res.getString("DGenerateSecretKey.jcbKeyAlg.tooltip"));
populateKeyAlgs();
loadKeySizes(secretKeySize);
jcbKeyAlg.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent evt) {
loadKeySizes(getSecretKeySize());
}
});
jpKeyAlg = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpKeyAlg.add(jlKeyAlg);
jpKeyAlg.add(jcbKeyAlg);
jsKeySize.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent evt) {
correctSecretKeySize();
}
});
jpOptions = new JPanel(new GridLayout(2, 1, 5, 5));
jpOptions.add(jpKeyAlg);
jpOptions.add(jpKeySize);
jpOptions.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new EtchedBorder()));
jbOK = new JButton(res.getString("DGenerateSecretKey.jbOK.text"));
jbOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
okPressed();
}
});
jbCancel = new JButton(res.getString("DGenerateSecretKey.jbCancel.text"));
jbCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
cancelPressed();
}
});
jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CANCEL_KEY);
jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent evt) {
cancelPressed();
}
});
jpButtons = PlatformUtil.createDialogButtonPanel(jbOK, jbCancel, false);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(jpOptions, BorderLayout.CENTER);
getContentPane().add(jpButtons, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent evt) {
closeDialog();
}
});
setResizable(false);
getRootPane().setDefaultButton(jbOK);
pack();
}
use of org.kse.crypto.secretkey.SecretKeyType in project keystore-explorer by kaikramer.
the class DGenerateSecretKey method correctSecretKeySize.
private void correctSecretKeySize() {
SecretKeyType secretKeyType = getSecretKeyType();
int secretKeySize = getSecretKeySize();
int validatedSecretKeySize = validateSecretKeySize(secretKeyType, secretKeySize);
if (validatedSecretKeySize != secretKeySize) {
jsKeySize.getModel().setValue(validatedSecretKeySize);
}
}
use of org.kse.crypto.secretkey.SecretKeyType in project keystore-explorer by kaikramer.
the class DGenerateSecretKey method loadKeySizes.
private void loadKeySizes(int secretKeySize) {
SecretKeyType secretKeyType = getSecretKeyType();
secretKeySize = validateSecretKeySize(secretKeyType, secretKeySize);
jsKeySize.setModel(new SpinnerNumberModel(secretKeySize, secretKeyType.minSize(), secretKeyType.maxSize(), secretKeyType.stepSize()));
jsKeySize.setEnabled(secretKeyType.maxSize() > secretKeyType.minSize());
}
Aggregations