Search in sources :

Example 6 with SecretKeyType

use of org.kse.crypto.secretkey.SecretKeyType in project keystore-explorer by kaikramer.

the class DProperties method createSecretKeyNodes.

private void createSecretKeyNodes(DefaultMutableTreeNode parentNode, SecretKey secretKey) {
    DefaultMutableTreeNode secretKeyNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.SecretKey"));
    parentNode.add(secretKeyNode);
    KeyInfo keyInfo = SecretKeyUtil.getKeyInfo(secretKey);
    String keyAlg = keyInfo.getAlgorithm();
    // Try and get friendly algorithm name for secret key
    SecretKeyType secretKeyType = SecretKeyType.resolveJce(keyAlg);
    if (secretKeyType != null) {
        keyAlg = secretKeyType.friendly();
    }
    secretKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(res.getString("DProperties.properties.Algorithm"), keyAlg)));
    Integer keySize = keyInfo.getSize();
    if (keySize != null) {
        secretKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(res.getString("DProperties.properties.KeySize"), "" + keyInfo.getSize())));
    } else {
        secretKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(res.getString("DProperties.properties.KeySize"), "?")));
    }
    String keyFormat = secretKey.getFormat();
    secretKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(res.getString("DProperties.properties.Format"), keyFormat)));
    String keyEncoded = "0x" + new BigInteger(1, secretKey.getEncoded()).toString(16).toUpperCase();
    secretKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(res.getString("DProperties.properties.Encoded"), keyEncoded)));
}
Also used : BigInteger(java.math.BigInteger) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyInfo(org.kse.crypto.KeyInfo) SecretKeyType(org.kse.crypto.secretkey.SecretKeyType) BigInteger(java.math.BigInteger)

Aggregations

SecretKeyType (org.kse.crypto.secretkey.SecretKeyType)6 BigInteger (java.math.BigInteger)2 KeyInfo (org.kse.crypto.KeyInfo)2 BorderLayout (java.awt.BorderLayout)1 FlowLayout (java.awt.FlowLayout)1 GridLayout (java.awt.GridLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 KeyStore (java.security.KeyStore)1 SecretKey (javax.crypto.SecretKey)1 AbstractAction (javax.swing.AbstractAction)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JSpinner (javax.swing.JSpinner)1 SpinnerNumberModel (javax.swing.SpinnerNumberModel)1