Generating Digital Certificates
Hello folks! I need some help and I think that I'm in right place... Please help me if you have time...
I want to create an application to create and export digital certificates. I know how to use keytool command and what I need is basically that command but in a form of GUI...
Here's my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
publicclass Pisca
{
public Pisca(){
final JFrame f =new JFrame("Certificate Authority");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setIconImage(new ImageIcon("BlueLace.PNG").getImage());
f.setResizable(false);
JFrame.setDefaultLookAndFeelDecorated(true);
f.setSize(400, 300);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
f.setLocation((d.width - f.getSize().width) / 2, (d.height - f.getSize().height) / 2);
Container cp = f.getContentPane();
cp.setLayout(new GridLayout(7,2));
JTextField tfName =new JTextField();
JTextField tfOrganizationalUnit =new JTextField();
JTextField tfOrganization =new JTextField();
JTextField tfCity =new JTextField();
JTextField tfState =new JTextField();
JTextField tfCountryCode =new JTextField();
tfCountryCode.setText("SR");
JLabel lblName =new JLabel("First and Last Name:");
JLabel lblOrganizationalUnit =new JLabel("Organizational Unit:");
JLabel lblOrganization =new JLabel("Organization:");
JLabel lblCity =new JLabel("City:");
JLabel lblState =new JLabel("State:");
JLabel lblCountryCode =new JLabel("Two-letter Contry Code:");
final JButton b =new JButton("Generisi");
b.setToolTipText("Generisite digitalni sertifikat.");
cp.add(lblName);
cp.add(tfName);
cp.add(lblOrganizationalUnit);
cp.add(tfOrganizationalUnit);
cp.add(lblOrganization);
cp.add(tfOrganization);
cp.add(lblCity);
cp.add(tfCity);
cp.add(lblState);
cp.add(tfState);
cp.add(lblCountryCode);
cp.add(tfCountryCode);
cp.add(new JLabel(""));
cp.add(b);
f.addWindowListener(new WindowAdapter(){
publicvoid windowClosing(WindowEvent e){
JOptionPane.showMessageDialog(f,"Hvala na koriscenju programa.","Milos Piscevic", JOptionPane.INFORMATION_MESSAGE);
}
});
b.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent e){
try
{
Runtime runtime = Runtime.getRuntime();
String temp ="CN=Name, OU=Some, O=Etc, L=Monaco, S=Nevermind, C=LT";
Process proc = runtime.exec("keytool -genkeypair -alias some_alias -keyalg RSA -sigalg SHA1withRSA -keysize 1024 -dname " + temp +" -keypass sifra -storepass somePass -keystore some_alias.keystore" -keystoretype JKS);
Process proc2 = runtime.exec("keytool -exportcert -alias....");
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(f,"Greska.","Milos Piscevic", JOptionPane.ERROR_MESSAGE);
}
}
});
f.setVisible(true);
}
publicstaticvoid main(String[] args)
{
Pisca p =new Pisca();
}
}
So what I want to do is, when user clicks on button b, to export a digital certificate in .cer format.
I've used keytool -genkeypair -alias ... -keyalg ... -sigalg ... -keystore ... command and that is ok. After I've created a keystore, then I used keytool -exportcert -alias ... -file name.cer ... command and I got my digital certificate.
In this application I want practically to simulate keytool but on a GUI basis, so when user clicks on button, I want to execute those two commands:
I tried something like this (I tried to put this code on actionPerformed event):
try
{
Runtime runtime = Runtime.getRuntime();
String temp ="CN=Name, OU=Some, O=Etc, L=Monaco, S=Nevermind, C=LT";
Process proc = runtime.exec("keytool -genkeypair -alias some_alias -keyalg RSA -sigalg SHA1withRSA -keysize 1024 -dname " + temp +" -keypass sifra -storepass somePass -keystore some_alias.keystore" -keystoretype JKS);
Process proc2 = runtime.exec("keytool -exportcert -alias....");
}
catch (IOException ex)
{
ex.printStackTrace();
}
But I got nothing!!!
How to solve this? If I can do that without using keytool, runtime, process and other classes, but something else, then what to use?
Message was edited by:
djalfirevic126

