use of org.kse.crypto.Password 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.Password in project keystore-explorer by kaikramer.
the class DImportKeyPairPkcs12 method loadKeyPair.
private Keypair loadKeyPair() {
String pkcs12Path = jtfPkcs12Path.getText().trim();
if (pkcs12Path.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairPkcs12.KeyPairRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
}
File pkcs12File = new File(pkcs12Path);
try {
Password pkcs12Password = new Password(jpfPassword.getPassword());
KeyStore pkcs12 = KeyStoreUtil.load(pkcs12File, pkcs12Password, KeyStoreType.PKCS12);
// Find a key pair in the PKCS #12 KeyStore
PrivateKey privKey = null;
ArrayList<Certificate> certsList = new ArrayList<Certificate>();
// Look for key pair entries first
for (Enumeration<?> aliases = pkcs12.aliases(); aliases.hasMoreElements(); ) {
String alias = (String) aliases.nextElement();
if (pkcs12.isKeyEntry(alias)) {
privKey = (PrivateKey) pkcs12.getKey(alias, pkcs12Password.toCharArray());
Certificate[] certs = pkcs12.getCertificateChain(alias);
if ((certs != null) && (certs.length > 0)) {
Collections.addAll(certsList, certs);
break;
}
}
}
// entries
if ((privKey == null) || (certsList.size() == 0)) {
for (Enumeration<?> aliases = pkcs12.aliases(); aliases.hasMoreElements(); ) {
String alias = (String) aliases.nextElement();
certsList.add(pkcs12.getCertificate(alias));
}
}
if ((privKey == null) || (certsList.size() == 0)) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs12.NoKeyPairPkcs12File.message"), pkcs12File.getName()), getTitle(), JOptionPane.INFORMATION_MESSAGE);
return null;
}
X509Certificate[] certs = X509CertUtil.convertCertificates(certsList.toArray(new Certificate[certsList.size()]));
return new Keypair(privKey, certs);
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs12.NoReadFile.message"), pkcs12File), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (Exception ex) {
Problem problem = createLoadPkcs12Problem(ex, pkcs12File);
DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairPkcs12.ProblemLoadingPkcs12.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return null;
}
}
use of org.kse.crypto.Password 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;
}
}
use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class DChangePassword method checkPassword.
private boolean checkPassword() {
Password oldPassword = new Password(jpfOld.getPassword());
Password firstPassword;
if (jpfFirst instanceof JPasswordQualityField) {
char[] firstPasswordChars = ((JPasswordQualityField) jpfFirst).getPassword();
if (firstPasswordChars == null) {
JOptionPane.showMessageDialog(this, res.getString("MinimumPasswordQualityNotMet.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
}
firstPassword = new Password(firstPasswordChars);
} else {
firstPassword = new Password(((JPasswordField) jpfFirst).getPassword());
}
Password confirmPassword = new Password(jpfConfirm.getPassword());
if (firstPassword.equals(confirmPassword)) {
this.oldPassword = oldPassword;
newPassword = firstPassword;
return true;
}
JOptionPane.showMessageDialog(this, res.getString("PasswordsNoMatch.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
}
use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class DGetNewPassword method checkPassword.
private boolean checkPassword() {
Password firstPassword;
if (jpfFirst instanceof JPasswordQualityField) {
char[] firstPasswordChars = ((JPasswordQualityField) jpfFirst).getPassword();
if (firstPasswordChars == null) {
JOptionPane.showMessageDialog(this, res.getString("MinimumPasswordQualityNotMet.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
}
firstPassword = new Password(firstPasswordChars);
} else {
firstPassword = new Password(((JPasswordField) jpfFirst).getPassword());
}
Password confirmPassword = new Password(jpfConfirm.getPassword());
if (firstPassword.equals(confirmPassword)) {
password = firstPassword;
return true;
}
JOptionPane.showMessageDialog(this, res.getString("PasswordsNoMatch.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
}
Aggregations