/* * CreateKeyDialog.java * * * ==================================================== Professional Data Security (PDS) http://crypto.brettlee.com ==================================================== Copyright (c) 2009-2011, Brett Lee All rights reserved. Portions Copyright (C) 1995-2008, Sun Microsystems, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the ORGANIZATION nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ============================================================================= */ package com.brettlee.crypto; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.ButtonGroup; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.border.EmptyBorder; import javax.swing.border.TitledBorder; import javax.swing.filechooser.FileNameExtensionFilter; /** * CreateKeyDialog - File-> New-> Key "Dialog" * */ class CreateKeyDialog { /** * */ private Gui mGui; JDialog createKeyDialog; JCheckBox setDefaultKeyCheckBox = new JCheckBox("", true); final JTextField keyAliasField = new JTextField(20); final JTextField keyStoreNameField = new JTextField("", 20); final JRadioButton buttonDES56 = new JRadioButton("56" , false); final JRadioButton button3DES112 = new JRadioButton("112" , false); final JRadioButton button3DES168 = new JRadioButton("168" , false); final JRadioButton buttonAES128 = new JRadioButton("128" , true); final JRadioButton buttonAES192 = new JRadioButton("192" , false); final JRadioButton buttonAES256 = new JRadioButton("256" , false); final ButtonGroup cipherStrength = new ButtonGroup(); final JPasswordField keyPassword1Field = new JPasswordField(15); final JPasswordField keyPassword2Field = new JPasswordField(15); final JPasswordField keyStorePasswordField = new JPasswordField(15); String newline = System.getProperty("line.separator"); public CreateKeyDialog (Gui theGui) { ///////////////////////////////////////////////////////////// // Build the Dialog mGui = theGui; createKeyDialog = new JDialog(mGui.mainFrame, "Create a New Key", true); JPanel contentPane = new JPanel(); GroupLayout layout = new GroupLayout(contentPane); contentPane.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); createKeyDialog.add(contentPane); FlowLayout flowLayoutLeft = new FlowLayout(); flowLayoutLeft.setAlignment(FlowLayout.LEFT); JPanel p1 = new JPanel(); JPanel p2 = new JPanel( flowLayoutLeft ); JPanel p3 = new JPanel( ); JPanel p4 = new JPanel( new GridLayout(0,1) ); JPanel p5 = new JPanel( new GridLayout(2,1) ); JPanel p6 = new JPanel( new GridLayout(1,1) ); JPanel p7 = new JPanel( ); layout.setHorizontalGroup( layout.createSequentialGroup() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(p1) .addComponent(p2) .addComponent(p3) .addComponent(p4) .addComponent(p5) .addComponent(p6) .addComponent(p7) )); layout.setVerticalGroup( layout.createSequentialGroup() .addComponent(p1) .addComponent(p2) .addComponent(p3) .addComponent(p4) .addComponent(p5) .addComponent(p6) .addComponent(p7) ); ///////////////////////////////////////////////////////////// // p1 - Title JLabel jlabel = new JLabel("Create a New Encryption Key"); p1.add(jlabel); // p2 - Key Name (Alias) p2.setBorder(new TitledBorder("Key Alias")); JPanel p2SubPanel = new JPanel(new FlowLayout()); p2.add(p2SubPanel); JLabel p2Label = new JLabel("Alias that will refer to this key: "); p2SubPanel.add(p2Label); p2SubPanel.add(keyAliasField); // p3 - Cipher p3.setBorder(new TitledBorder("Encryption Key")); JPanel p3SubPanelUpper = new JPanel( new GridLayout(2,2) ); JPanel p3SubPanelLower = new JPanel(flowLayoutLeft); p3SubPanelUpper.setBorder(new EmptyBorder(5,5,5,5)); p3SubPanelLower.setBorder(new TitledBorder("Cipher / Strength")); GroupLayout p3layout = new GroupLayout(p3); p3.setLayout(p3layout); p3layout.setAutoCreateGaps(true); p3layout.setAutoCreateContainerGaps(false); p3layout.setHorizontalGroup( p3layout.createSequentialGroup() .addGroup(p3layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(p3SubPanelUpper) .addComponent(p3SubPanelLower) )); p3layout.setVerticalGroup( p3layout.createSequentialGroup() .addComponent(p3SubPanelUpper) .addComponent(p3SubPanelLower) ); // Upper Panel Part 1 for p3 JLabel usingUnlimitedStrengthKeys = new JLabel("Risks using AES 192/256."); p3SubPanelUpper.add(usingUnlimitedStrengthKeys); JButton usingUnlimitedStrengthKeysDialog = new JButton("* Click Here *"); usingUnlimitedStrengthKeysDialog.setBorderPainted(false); usingUnlimitedStrengthKeysDialog.setOpaque(false); usingUnlimitedStrengthKeysDialog.setContentAreaFilled(false); usingUnlimitedStrengthKeysDialog.setForeground(java.awt.Color.BLUE); Gui.enterPressesWhenFocused(usingUnlimitedStrengthKeysDialog); usingUnlimitedStrengthKeysDialog.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int maxAESsize = 0; try { maxAESsize = javax.crypto.Cipher.getMaxAllowedKeyLength("AES"); } catch (Exception e) { } String jceInstalled; if (maxAESsize > 128) { jceInstalled = "\"Unlimited Strength\""; } else { jceInstalled = "\"Strong\""; } JFrame frame = new JFrame(); JOptionPane.showMessageDialog( frame, newline + "Cryptography developed in the US is regulated by the Government. Implications of this" + newline + "are many, including limitations on the amount of cryptographic functionality that may" + newline + "be delivered with the Java runtime (JRE)." + newline + newline + "As an example, Sun's JRE is delivered with a default level of functionality known as \"Strong\"" + newline + "encryption. In this mode the JRE can create cryptographic keys of any size, however ciphers" + newline + "(the things that encrypt and decrypt) are limited to using only the \"Strong\" keys." + newline + newline + "For the symmetric algorithms used in this application, \"Strong\" cryptography supports:" + newline + "DES - 56 bits" + newline + "3DES - 112 and 168 bits" + newline + "AES - 128 bits" + newline + newline + "In order to use the higher strength keys with the AES algorithm, policy files that enable" + newline + "\"Unlimited Strength\" cryptography need to be installed. Having made a quick check of" + newline + "this system, it appears that AES encryption up to " + maxAESsize + " bytes is supported," + newline + "indicating that the " + jceInstalled + " JCE policy is installed. Note that this is also" + newline + "seen on the title bar of main window." + newline + newline + "If you choose to use AES cryptography with key sizes greater than 128 bits, then you will" + newline + "only be able to use those keys to encrypt and decrypt on systems with Unlimited Cryptography." + newline + newline + "In practice, an AES cipher of 128 bits provides suitable protection to for our needs." + newline + "It is the recommended cipher for users of this application." + newline + newline , "Risks using AES 192/256", JOptionPane.INFORMATION_MESSAGE, Gui.createImageIcon("images/PDS_Logo-32.png")); } }); p3SubPanelUpper.add(usingUnlimitedStrengthKeysDialog); // Upper Panel Part 2 for p3 JLabel disabledKeysLabel = new JLabel("Some key strengths disabled?"); p3SubPanelUpper.add(disabledKeysLabel); JButton disabledKeysDialog = new JButton("* Click Here *"); disabledKeysDialog.setBorderPainted(false); disabledKeysDialog.setOpaque(false); disabledKeysDialog.setContentAreaFilled(false); disabledKeysDialog.setForeground(java.awt.Color.BLUE); Gui.enterPressesWhenFocused(disabledKeysDialog); disabledKeysDialog.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int maxAESsize = 0; try { maxAESsize = javax.crypto.Cipher.getMaxAllowedKeyLength("AES"); } catch (Exception e) { } String jceInstalled; if (maxAESsize > 128) { jceInstalled = "\"Unlimited Strength\""; } else { jceInstalled = "\"Strong\""; } JFrame frame = new JFrame(); JOptionPane.showMessageDialog( frame, newline + "As described in the \"Risk using AES 192/256\" section, Sun's JRE will provide" + newline + "support for either \"Strong\" or \"Unlimited\" cryptography. A check of this" + newline + "system indicates that that AES encryption up to " + maxAESsize + " bytes is" + newline + "supported, thus the " + jceInstalled + " JCE policy is installed (note that" + newline + "this is also seen on the title bar of main window)." + newline + newline + "If the AES 192/256 ciphers are not supported by the current JVM, this application" + newline + "will not support the creation of AES 192/256 bit keys. Note that this is not a" + newline + "limitation of the JRE but instead of the application. Should you wish to create" + newline + "keys that are supported by the higher strength ciphers, please install the \"Unlimited\"" + newline + "strength policy files and restart this application." + newline + newline + newline , "JRE Key Availability", JOptionPane.INFORMATION_MESSAGE, Gui.createImageIcon("images/PDS_Logo-32.png")); } }); p3SubPanelUpper.add(disabledKeysDialog); // Lower Panel for p3 JLabel p3Label = new JLabel("Select the cipher and strength: "); p3SubPanelLower.add(p3Label, BorderLayout.WEST ); JPanel p3SubPanel2 = new JPanel(new GridLayout(2,3)); p3SubPanelLower.add(p3SubPanel2); JLabel AESLabel = new JLabel("AES: "); JLabel DES3Label = new JLabel("3DES: "); JLabel DESLabel = new JLabel("DES: "); // //////////////////////////////////////////////////////////////// // Are the Unlimited Strength Jurisdiction Policy Files Installed? // int maxAESsize = 0; try { maxAESsize = javax.crypto.Cipher.getMaxAllowedKeyLength("AES"); } catch (Exception e) { } if (maxAESsize <= 128) { buttonAES192.setEnabled(false); buttonAES256.setEnabled(false); } cipherStrength.add(buttonDES56); cipherStrength.add(button3DES112); cipherStrength.add(button3DES168); cipherStrength.add(buttonAES128); cipherStrength.add(buttonAES192); cipherStrength.add(buttonAES256); GroupLayout cipherLayout = new GroupLayout(p3SubPanel2); p3SubPanel2.setLayout(cipherLayout); cipherLayout.setAutoCreateGaps(true); cipherLayout.setAutoCreateContainerGaps(true); cipherLayout.setHorizontalGroup( cipherLayout.createSequentialGroup() .addGroup(cipherLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(DESLabel) .addComponent(DES3Label) .addComponent(AESLabel) ).addGroup(cipherLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(buttonDES56) .addComponent(button3DES112) .addComponent(buttonAES128) ).addGroup(cipherLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(button3DES168) .addComponent(buttonAES192) ).addGroup(cipherLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(buttonAES256) ) ); cipherLayout.setVerticalGroup( cipherLayout.createSequentialGroup() .addGroup(cipherLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(DESLabel) .addComponent(buttonDES56) ).addGroup(cipherLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(DES3Label) .addComponent(button3DES112) .addComponent(button3DES168) ).addGroup(cipherLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(AESLabel) .addComponent(buttonAES128) .addComponent(buttonAES192) .addComponent(buttonAES256) ) ); // p4 - Key passphrase p4.setBorder(new TitledBorder("Key Passphrase")); JPanel p4SubPanelFlow = new JPanel(flowLayoutLeft); p4.add(p4SubPanelFlow); JPanel p4SubPanel = new JPanel(new GridLayout(2,2)); p4SubPanelFlow.add(p4SubPanel); keyPassword2Field.setEnabled(true); p4SubPanel.add(new JLabel("Passphrase: "), BorderLayout.WEST); p4SubPanel.add(keyPassword1Field, BorderLayout.WEST); p4SubPanel.add(new JLabel("Passphrase (again): "), BorderLayout.WEST); p4SubPanel.add(keyPassword2Field, BorderLayout.WEST); // p5 - Browse to KeyStore p5.setBorder(new TitledBorder("KeyStore Association")); JPanel p5SubPanel = new JPanel(flowLayoutLeft); p5.add(p5SubPanel); JLabel p5Label = new JLabel("KeyStore that will hold this key: "); p5SubPanel.add(p5Label); p5SubPanel.add(keyStoreNameField); keyStoreNameField.setEnabled(false); JButton iconOpen = new JButton(Gui.createImageIcon("images/folder.gif", 28)); iconOpen.setFocusable(false); Gui.enterPressesWhenFocused(iconOpen); iconOpen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { browseToKeyStoreActionPerformed(evt); } }); iconOpen.setToolTipText("Open"); p5SubPanel.add(iconOpen); JPanel p5SubPanel2 = new JPanel( flowLayoutLeft ); p5.add(p5SubPanel2); p5SubPanel2.add(new JLabel("KeyStore Passphrase: "), BorderLayout.WEST); keyStorePasswordField.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { if ( keyStorePasswordField.getPassword().length > 0 ) { createKeyInstanceActionPerformed(evt); } } } ); p5SubPanel2.add(keyStorePasswordField, BorderLayout.WEST); // p6 - Set as Default Key p6.setBorder(new TitledBorder("Default Key")); JPanel p6SubPanel = new JPanel( flowLayoutLeft ); p6.add(p6SubPanel); JLabel p6Label = new JLabel("Make this key my default key"); p6SubPanel.add(p6Label); p6SubPanel.add(setDefaultKeyCheckBox); // p7 - Create & Cancel Buttons JButton jButtonCreate = new JButton("Create"); jButtonCreate.setMnemonic(KeyEvent.VK_R); Gui.enterPressesWhenFocused(jButtonCreate); jButtonCreate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { createKeyInstanceActionPerformed(evt); } }); p7.add(jButtonCreate); JButton jButtonCancel = new JButton("Cancel"); jButtonCancel.setMnemonic(KeyEvent.VK_C); Gui.enterPressesWhenFocused(jButtonCancel); jButtonCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // System.out.println("Canceling..."); createKeyDialog.setVisible(false); createKeyDialog.dispose(); } }); p7.add(jButtonCancel); ///////////////////////////////////////////////////////////// // Finish up createKeyDialog.setTitle("Professional Data Security (PDS) - Create New Key"); createKeyDialog.pack(); createKeyDialog.setLocationRelativeTo(null); createKeyDialog.setVisible(true); } /////////////////////////////////////////////////////////////////////// /** * Listeners for the CreateKeyDialog inner class * */ /////////////////////////////////////////////////////////////////////// public void createKeyInstanceActionPerformed(ActionEvent e) { // System.out.println("Create"); JFrame frame = new JFrame(); String keyAlias = keyAliasField.getText(); // System.out.println("KeyStore Name (Alias): " + keyAlias); if ( keyAlias.length() == 0 ) { // notify if failure JOptionPane.showMessageDialog( frame, "Key Alias cannot be empty.", "Key Alias", JOptionPane.WARNING_MESSAGE); return; } String keyCipher = "unknown"; String keyBitString = "unknown"; if ( buttonDES56.isSelected() ) { keyBitString = "56"; keyCipher = "DES"; } else if ( button3DES112.isSelected() ) { keyBitString = "112"; keyCipher = "DESede"; } else if ( button3DES168.isSelected() ) { keyBitString = "168"; keyCipher = "DESede"; } else if ( buttonAES128.isSelected() ) { keyBitString = "128"; keyCipher = "AES"; } else if ( buttonAES192.isSelected() ) { keyBitString = "192"; keyCipher = "AES"; } else if ( buttonAES256.isSelected() ) { keyBitString = "256"; keyCipher = "AES"; } else { System.out.println("Unable to get cipher type / strength:"); System.out.println("Key Cipher : " + keyCipher); System.out.println("Key Bits: " + keyBitString); } // System.out.println("Key Cipher : " + keyCipher); // System.out.println("Key Bits: " + keyBitString); int keyBits = 56; try { keyBits = new Integer(keyBitString).intValue(); } catch ( NumberFormatException createIntegerException ) { System.out.println("Error creating Integer: " + createIntegerException); } char[] keyPass1 = keyPassword1Field.getPassword(); char[] keyPass2 = keyPassword2Field.getPassword(); // System.out.print("Key Passphrase : "); // for ( int i = 0; i < keyPass1.length; i++ ) { // System.out.print( keyPass1[i] ); // } // System.out.println(); // System.out.print("Key Passphrase (again) : "); // for ( int i = 0; i < keyPass2.length; i++ ) { // System.out.print( keyPass2[i] ); // } // System.out.println(); // Was the first key pass provided and correct if ( ! (keyPass1.length >= 8) ) { // notify if failure JOptionPane.showMessageDialog( frame, "Key passphrase must be at least 8 characters, " + newline + "containing both upper case and lower case characters " + newline + "as well as some other character.", "Passphrase empty", JOptionPane.WARNING_MESSAGE); return; } // Check for correct syntax boolean upper = false; // set to true if test passes boolean lower = false; // set to true if test passes boolean other = false; // set to true if test passes // Check for upper case first for ( int i = 0; i < keyPass1.length; i++ ) { for ( int n = 65; n <= 90; n++ ) { if ( ( (int) keyPass1[i] ) == n ) { upper = true; n = 91; i = keyPass1.length; } } } // System.out.println("Contained upper: " + upper); // Check for lower case next for ( int i = 0; i < keyPass1.length; i++ ) { for ( int n = 97; n <= 122; n++ ) { if ( ( (int) keyPass1[i] ) == n ) { lower = true; n = 123; i = keyPass1.length; } } } // System.out.println("Contained lower: " + lower); // Check for existance of another char last for ( int i = 0; i < keyPass1.length; i++ ) { boolean otherUpper = false; boolean otherLower = false; // Is it an upper case char ? for ( int n = 65; n <= 90; n++ ) { if ( ( (int) keyPass1[i] ) == n ) { otherUpper = true; n = 91; } } // If not upper, then is it lower case char? if ( ! otherUpper ) { for ( int j = 97; j <= 122; j++ ) { if ( ( (int) keyPass1[i] ) == j ) { otherLower = true; j = 123; } } } if ( ( ! otherUpper ) && ( ! otherLower ) ) { other = true; i = keyPass1.length; } } // System.out.println("Contained other: " + other); if( ! ( upper && lower && other ) ) { // notify if failure JOptionPane.showMessageDialog( frame, "Key passphrase must be at least 8 characters, " + newline + "containing both upper case and lower case characters " + newline + "as well as some other character.", "Passphrase empty", JOptionPane.WARNING_MESSAGE); return; } // Did the passwords match if ( ! java.util.Arrays.equals(keyPass1,keyPass2) ) { // notify if failure JOptionPane.showMessageDialog( frame, "Key passphrases did not match.", "Passphrase mismatch", JOptionPane.WARNING_MESSAGE); return; } // Was the KeyStore name provided if ( ksName == null ) { // notify if failure JOptionPane.showMessageDialog( frame, "KeyStore name cannot be empty.", "KeyStore name", JOptionPane.WARNING_MESSAGE); return; } char[] ksPass = keyStorePasswordField.getPassword(); // Was the first key pass provided if ( ksPass.length == 0 ) { // notify if failure JOptionPane.showMessageDialog( frame, "KeyStore passphrase cannot be empty.", "Passphrase empty", JOptionPane.WARNING_MESSAGE); return; } try { if ( new CryptoKey().checkKeyExists ( ksName, ksPass, keyAlias ) == 0 ) { int n = JOptionPane.showOptionDialog( frame, "A key with this name currently exits." + newline + "If you continue, the existing Key will be destroyed." + newline + "Any data files that have been encrypted by this key will be lost." + newline + "Continue?", "Key exists", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[] {"Yes", "No"}, "No"); if ( n != 0 ) { // System.out.println("Canceling..."); // Scrub the passwords for ( int i = 0; i < ksPass.length; i++ ) { ksPass[i] = '0'; } return; } } } catch (Exception ex) { } // System.out.println("Will this key be the default key?"); if ( setDefaultKeyCheckBox.isSelected() ) { // System.out.println("Setting key as default."); // get KeyStore name - String "ksName" // System.out.println("Using KeyStore: " + ksName); // get key alias - String "keyAlias" // System.out.println("Using Key Alias: " + keyAlias); // - update state object w/ ksName and keyAlias mGui.stateObject.setDefaultKeyStore( ksName ); mGui.stateObject.setDefaultKeyAlias( keyAlias ); mGui.stateObject.setHaveDefaults( true ); // Save in-memory state to persistent storage. if (! mGui.stateObject.saveState()) { System.out.println("Error saving current state."); } } // System.out.println("Creating Key ..."); // System.out.println("KeyStore Name: " + ksName); boolean closeDialog = true; try { new CryptoKey().createKey( ksName, ksPass, keyCipher, keyBits, keyPass1, keyAlias ); JOptionPane.showMessageDialog( frame, "Key with alias \"" + keyAlias + "\" successfully created in:" + newline + ksName + newline , "Success", JOptionPane.INFORMATION_MESSAGE, Gui.createImageIcon("images/PDS_Logo-32.png")); } catch (Exception createKeyException ) { // notify if failure System.out.println("Error creating Key: " + createKeyException); closeDialog = false; JOptionPane.showMessageDialog( frame, "Error Creating the new Key: " + newline + createKeyException + newline + newline + "Retry again using different credentials, or select a different KeyStore.", "Error Creating Key", JOptionPane.ERROR_MESSAGE); } finally { // Scrub the passphrases // System.out.println("Scrubbing passphrases in Gui.createKeyDialog..."); for ( int i = 0; i < keyPass1.length; i++ ) { keyPass1[i] = '0'; } for ( int i = 0; i < keyPass2.length; i++ ) { keyPass2[i] = '0'; } for ( int i = 0; i < ksPass.length; i++ ) { ksPass[i] = '0'; } // System.out.println("Closing Create Key Dialog"); if ( closeDialog ) { createKeyDialog.setVisible(false); createKeyDialog.dispose(); } } } // // Listener Action Item for Browse to KeyStore // JFrame chooserFrame = new JFrame(); String ksName; private void browseToKeyStoreActionPerformed(ActionEvent evt) { JFileChooser fileChooser; if ( mGui.stateObject.getDefaultKeyStoreDir() != null ) { fileChooser = new JFileChooser ( mGui.stateObject.getDefaultKeyStoreDir() ); } else { fileChooser = new JFileChooser ( mGui.runTimePath ); } fileChooser.setDialogTitle( "Select the KeyStore" ); fileChooser.setApproveButtonText("OK"); FileNameExtensionFilter filterPDS = new FileNameExtensionFilter("Professional Data Security Files (PDS)", "PDS"); FileNameExtensionFilter filterJCEKS = new FileNameExtensionFilter("Java Cryptographic Extension (JCE) KeyStores (JCEKS)", "JCEKS"); FileNameExtensionFilter filterJKS = new FileNameExtensionFilter("Java KeyStores (JKS)", "JKS"); FileNameExtensionFilter filterKeyStores = new FileNameExtensionFilter("Java KeyStores (JCEKS, JKS)", "JCEKS", "JKS"); fileChooser.addChoosableFileFilter( filterJKS ); fileChooser.addChoosableFileFilter( filterJCEKS ); fileChooser.addChoosableFileFilter( filterPDS ); fileChooser.addChoosableFileFilter(filterKeyStores); int returnVal = fileChooser.showOpenDialog(chooserFrame); if ( returnVal == 0 ) { // Get Absolute Path: ksName = fileChooser.getSelectedFile().getPath(); // System.out.print("KeyStore: " + ksName + newline); keyStoreNameField.setText( ksName ); keyStoreNameField.setEnabled(true); keyStoreNameField.repaint(); } else if ( returnVal == 1 ) { // System.out.print("Canceling..." + newline); } else { System.out.print("Error: " + returnVal + newline); } } }