use of org.kse.crypto.KeyInfo in project keystore-explorer by kaikramer.
the class DProperties method createPublicKeyNodes.
private void createPublicKeyNodes(DefaultMutableTreeNode parentNode, PublicKey publicKey) throws CryptoException {
DefaultMutableTreeNode publicKeyNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.PublicKey"));
parentNode.add(publicKeyNode);
KeyInfo keyInfo = KeyPairUtil.getKeyInfo(publicKey);
String keyAlg = keyInfo.getAlgorithm();
publicKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(res.getString("DProperties.properties.Algorithm"), keyAlg)));
Integer keySize = keyInfo.getSize();
if (keySize != null) {
publicKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(res.getString("DProperties.properties.KeySize"), "" + keyInfo.getSize())));
} else {
publicKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(res.getString("DProperties.properties.KeySize"), "?")));
}
String keyFormat = publicKey.getFormat();
publicKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(res.getString("DProperties.properties.Format"), keyFormat)));
String keyEncoded = "0x" + new BigInteger(1, publicKey.getEncoded()).toString(16).toUpperCase();
publicKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(res.getString("DProperties.properties.Encoded"), keyEncoded)));
if (publicKey instanceof RSAPublicKey) {
RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
String publicExponent = MessageFormat.format(res.getString("DProperties.properties.public.rsa.PublicExponent"), "0x" + rsaPublicKey.getPublicExponent().toString(16).toUpperCase());
publicKeyNode.add(new DefaultMutableTreeNode(publicExponent));
String modulus = MessageFormat.format(res.getString("DProperties.properties.public.rsa.Modulus"), "0x" + rsaPublicKey.getModulus().toString(16).toUpperCase());
publicKeyNode.add(new DefaultMutableTreeNode(modulus));
} else if (publicKey instanceof DSAPublicKey) {
DSAPublicKey dsaPublicKey = (DSAPublicKey) publicKey;
DSAParams dsaParams = dsaPublicKey.getParams();
String primeModulusP = MessageFormat.format(res.getString("DProperties.properties.public.dsa.PrimeModulusP"), "0x" + dsaParams.getP().toString(16).toUpperCase());
publicKeyNode.add(new DefaultMutableTreeNode(primeModulusP));
String primeQ = MessageFormat.format(res.getString("DProperties.properties.public.dsa.PrimeQ"), "0x" + dsaParams.getQ().toString(16).toUpperCase());
publicKeyNode.add(new DefaultMutableTreeNode(primeQ));
String generatorG = MessageFormat.format(res.getString("DProperties.properties.public.dsa.GeneratorG"), "0x" + dsaParams.getG().toString(16).toUpperCase());
publicKeyNode.add(new DefaultMutableTreeNode(generatorG));
String publicKeyY = MessageFormat.format(res.getString("DProperties.properties.public.dsa.PublicKeyY"), "0x" + dsaPublicKey.getY().toString(16).toUpperCase());
publicKeyNode.add(new DefaultMutableTreeNode(publicKeyY));
}
}
use of org.kse.crypto.KeyInfo in project keystore-explorer by kaikramer.
the class DViewCertificate method populateDetails.
private void populateDetails() {
X509Certificate cert = getSelectedCertificate();
if (cert == null) {
jdnSubject.setEnabled(false);
jdnIssuer.setEnabled(false);
jbViewPublicKeyDetails.setEnabled(false);
jcfFingerprint.setEnabled(false);
jbExtensions.setEnabled(false);
jbPem.setEnabled(false);
jbAsn1.setEnabled(false);
jtfVersion.setText("");
jdnSubject.setDistinguishedName(null);
jdnIssuer.setDistinguishedName(null);
jtfSerialNumber.setText("");
jtfValidFrom.setText("");
jtfValidUntil.setText("");
jtfPublicKey.setText("");
jtfSignatureAlgorithm.setText("");
jcfFingerprint.setEncodedCertificate(null);
} else {
jdnSubject.setEnabled(true);
jdnIssuer.setEnabled(true);
jbViewPublicKeyDetails.setEnabled(true);
jbExtensions.setEnabled(true);
jbPem.setEnabled(true);
jbAsn1.setEnabled(true);
try {
Date currentDate = new Date();
Date startDate = cert.getNotBefore();
Date endDate = cert.getNotAfter();
boolean notYetValid = currentDate.before(startDate);
boolean noLongerValid = currentDate.after(endDate);
jtfVersion.setText(Integer.toString(cert.getVersion()));
jtfVersion.setCaretPosition(0);
jdnSubject.setDistinguishedName(X500NameUtils.x500PrincipalToX500Name(cert.getSubjectX500Principal()));
jdnIssuer.setDistinguishedName(X500NameUtils.x500PrincipalToX500Name(cert.getIssuerX500Principal()));
jtfSerialNumber.setText("0x" + new BigInteger(1, cert.getSerialNumber().toByteArray()).toString(16).toUpperCase());
jtfSerialNumber.setCaretPosition(0);
jtfValidFrom.setText(StringUtils.formatDate(startDate));
if (notYetValid) {
jtfValidFrom.setText(MessageFormat.format(res.getString("DViewCertificate.jtfValidFrom.notyetvalid.text"), jtfValidFrom.getText()));
jtfValidFrom.setForeground(Color.red);
} else {
jtfValidFrom.setForeground(jtfVersion.getForeground());
}
jtfValidFrom.setCaretPosition(0);
jtfValidUntil.setText(StringUtils.formatDate(endDate));
if (noLongerValid) {
jtfValidUntil.setText(MessageFormat.format(res.getString("DViewCertificate.jtfValidUntil.expired.text"), jtfValidUntil.getText()));
jtfValidUntil.setForeground(Color.red);
} else {
jtfValidUntil.setForeground(jtfVersion.getForeground());
}
jtfValidUntil.setCaretPosition(0);
KeyInfo keyInfo = KeyPairUtil.getKeyInfo(cert.getPublicKey());
jtfPublicKey.setText(keyInfo.getAlgorithm());
Integer keySize = keyInfo.getSize();
if (keySize != null) {
jtfPublicKey.setText(MessageFormat.format(res.getString("DViewCertificate.jtfPublicKey.text"), jtfPublicKey.getText(), "" + keySize));
} else {
jtfPublicKey.setText(MessageFormat.format(res.getString("DViewCertificate.jtfPublicKey.text"), jtfPublicKey.getText(), "?"));
}
jtfPublicKey.setCaretPosition(0);
jtfSignatureAlgorithm.setText(X509CertUtil.getCertificateSignatureAlgorithm(cert));
jtfSignatureAlgorithm.setCaretPosition(0);
byte[] encodedCertificate;
try {
encodedCertificate = cert.getEncoded();
} catch (CertificateEncodingException ex) {
throw new CryptoException(res.getString("DViewCertificate.NoGetEncodedCert.exception.message"), ex);
}
jcfFingerprint.setEncodedCertificate(encodedCertificate);
jcfFingerprint.setFingerprintAlg(ApplicationSettings.getInstance().getCertificateFingerprintType());
Set<?> critExts = cert.getCriticalExtensionOIDs();
Set<?> nonCritExts = cert.getNonCriticalExtensionOIDs();
if (critExts != null && critExts.size() != 0 || nonCritExts != null && nonCritExts.size() != 0) {
jbExtensions.setEnabled(true);
} else {
jbExtensions.setEnabled(false);
}
} catch (CryptoException ex) {
DError dError = new DError(this, ex);
dError.setLocationRelativeTo(this);
dError.setVisible(true);
dispose();
}
}
}
use of org.kse.crypto.KeyInfo in project keystore-explorer by kaikramer.
the class DViewPrivateKey method populateDialog.
private void populateDialog() throws CryptoException {
KeyInfo keyInfo = KeyPairUtil.getKeyInfo(privateKey);
jtfAlgorithm.setText(keyInfo.getAlgorithm());
Integer keyLength = keyInfo.getSize();
if (keyLength != null) {
jtfKeySize.setText(MessageFormat.format(res.getString("DViewPrivateKey.jtfKeySize.text"), "" + keyLength));
} else {
jtfKeySize.setText(MessageFormat.format(res.getString("DViewPrivateKey.jtfKeySize.text"), "?"));
}
jtfFormat.setText(privateKey.getFormat());
jtfEncoded.setText("0x" + new BigInteger(1, privateKey.getEncoded()).toString(16).toUpperCase());
jtfEncoded.setCaretPosition(0);
if ((privateKey instanceof RSAPrivateKey) || (privateKey instanceof DSAPrivateKey)) {
jbFields.setEnabled(true);
} else {
jbFields.setEnabled(false);
}
}
use of org.kse.crypto.KeyInfo in project keystore-explorer by kaikramer.
the class DViewPublicKey method populateDialog.
private void populateDialog() throws CryptoException {
KeyInfo keyInfo = KeyPairUtil.getKeyInfo(publicKey);
jtfAlgorithm.setText(keyInfo.getAlgorithm());
Integer keyLength = keyInfo.getSize();
if (keyLength != null) {
jtfKeySize.setText(MessageFormat.format(res.getString("DViewPublicKey.jtfKeySize.text"), "" + keyLength));
} else {
jtfKeySize.setText(MessageFormat.format(res.getString("DViewPublicKey.jtfKeySize.text"), "?"));
}
jtfFormat.setText(publicKey.getFormat());
jtfEncoded.setText("0x" + new BigInteger(1, publicKey.getEncoded()).toString(16).toUpperCase());
jtfEncoded.setCaretPosition(0);
if ((publicKey instanceof RSAPublicKey) || (publicKey instanceof DSAPublicKey)) {
jbFields.setEnabled(true);
} else {
jbFields.setEnabled(false);
}
}
use of org.kse.crypto.KeyInfo 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);
}
Aggregations