use of org.kse.crypto.privatekey.PrivateKeyUnencryptedException in project keystore-explorer by kaikramer.
the class DImportKeyPairPkcs8 method loadPrivateKey.
private PrivateKey loadPrivateKey() {
String privateKeyPath = jtfPrivateKeyPath.getText().trim();
if (privateKeyPath.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairPkcs8.PrivateKeyRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
}
File privateKeyFile = new File(privateKeyPath);
try {
PrivateKey privateKey = null;
if (!jcbEncrypted.isSelected()) {
privateKey = Pkcs8Util.load(new FileInputStream(privateKeyFile));
} else {
Password password = new Password(jpfPassword.getPassword());
privateKey = Pkcs8Util.loadEncrypted(new FileInputStream(privateKeyFile), password);
}
return privateKey;
} catch (PrivateKeyEncryptedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.PrivateKeyEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
jcbEncrypted.setSelected(true);
return null;
} catch (PrivateKeyUnencryptedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.PrivateKeyNotEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
jcbEncrypted.setSelected(false);
return null;
} catch (PrivateKeyPbeNotSupportedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.PrivateKeyPbeNotSupported.message"), ex.getUnsupportedPbe()), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.NoReadFile.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (Exception ex) {
Problem problem = createLoadPkcs8Problem(ex, privateKeyFile);
DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairPkcs8.ProblemLoadingPkcs8.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return null;
}
}
use of org.kse.crypto.privatekey.PrivateKeyUnencryptedException in project keystore-explorer by kaikramer.
the class DImportKeyPairOpenSsl method loadPrivateKey.
private PrivateKey loadPrivateKey() {
String privateKeyPath = jtfPrivateKeyPath.getText().trim();
if (privateKeyPath.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairOpenSsl.PrivateKeyRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
}
File privateKeyFile = new File(privateKeyPath);
try {
PrivateKey privateKey = null;
if (!jcbEncrypted.isSelected()) {
privateKey = OpenSslPvkUtil.load(new FileInputStream(privateKeyFile));
} else {
Password password = new Password(jpfPassword.getPassword());
privateKey = OpenSslPvkUtil.loadEncrypted(new FileInputStream(privateKeyFile), password);
}
return privateKey;
} catch (PrivateKeyEncryptedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.PrivateKeyEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
jcbEncrypted.setSelected(true);
return null;
} catch (PrivateKeyUnencryptedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.PrivateKeyNotEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
jcbEncrypted.setSelected(false);
return null;
} catch (PrivateKeyPbeNotSupportedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.PrivateKeyPbeNotSupported.message"), ex.getUnsupportedPbe()), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.NoReadFile.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (Exception ex) {
Problem problem = createLoadOpenSslProblem(ex, privateKeyFile);
DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairOpenSsl.ProblemLoadingOpenSsl.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return null;
}
}
use of org.kse.crypto.privatekey.PrivateKeyUnencryptedException in project keystore-explorer by kaikramer.
the class DImportKeyPairPvk method loadPrivateKey.
private PrivateKey loadPrivateKey() {
String privateKeyPath = jtfPrivateKeyPath.getText().trim();
if (privateKeyPath.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairPvk.PrivateKeyRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
}
File privateKeyFile = new File(privateKeyPath);
try {
PrivateKey privateKey = null;
if (!jcbEncrypted.isSelected()) {
privateKey = MsPvkUtil.load(new FileInputStream(privateKeyFile));
} else {
Password password = new Password(jpfPassword.getPassword());
privateKey = MsPvkUtil.loadEncrypted(new FileInputStream(privateKeyFile), password);
}
return privateKey;
} catch (PrivateKeyEncryptedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPvk.PrivateKeyEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
jcbEncrypted.setSelected(true);
return null;
} catch (PrivateKeyUnencryptedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPvk.PrivateKeyNotEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
jcbEncrypted.setSelected(false);
return null;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPvk.NoReadFile.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (Exception ex) {
Problem problem = createLoadPvkProblem(ex, privateKeyFile);
DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairPvk.ProblemLoadingPvk.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return null;
}
}
Aggregations