CARead.java file code:
Common class CARead extends JPanel {
Private string CA _ Name
Private string CA_ItemData[][] = new string [9] [2];
Private String[] columnNames = {"Certificate field tag", "content"};
Public CARead (string certificate name)
CA _ Name = CertName
/* Three panels are used to display certificate contents */
JTabbedPane tabbedPane = new JTabbedPane();
JPanel panel normal = new JPanel();
Tab bepane. add tab ("general information", panel normal);
JPanel panel all = new JPanel();
panel all . set layout(new BorderLayout());
Tab bepane. add tab ("all information", pane);
JPanel panel base 64 = new JPanel();
panel base 64 . set layout(new BorderLayout());
Tab be pane. addtab ("information in base64 encoded form", panel base64);
/* Read the general information of the certificate */
read _ Normal(panel Normal);
/* Read the contents of the certificate file string */
read _ Bin(panel all);
/* Read the certificate file information in Base64 encoding format */
read _ Raw(panel base 64);
tabbedepane . setselectedindex(0);
set layout(new GridLayout( 1, 1));
Add (tabbedepane);
}
Private int Read_Normal(JPanel panel)
String field;
Try {
Certification factory certificate_factory = certification factory
. getInstance(" x . 509 ");
file inputstream file _ inputstream = new file inputstream(CA _ Name);
x509 certificate x509 certificate =(x509 certificate)certificate _ factory
. generate certificate(file _ inputstream);
field = x509 certificate . gettype();
CA _ item data[0][0]= " type ";
CA _ item data[0][ 1]= Field;
field = integer . tostring(x509 certificate . getversion());
CA _ item data[ 1][0]= " version ";
CA _ item data[ 1][ 1]= Field;
field = x509 certificate . getsubjectdn()。 getName();
CA _ item data[2][0]= " title ";
CA _ item data[2][ 1]= Field;
field = x509 certificate . getnotbefore()。 toString(); //Get the start effective date
CA_ItemData[3][0] = "effective date";
CA _ item data[3][ 1]= Field;
Field = certificate. getNotAfter()。 toString(); //Get the expiration date
CA _ item data[4][0]= " Deadline ";
CA _ item data[4][ 1]= Field;
field = x509 certificate . get serial number()。 toString( 16); //Get the serial number
CA_ItemData[5][0] = "serial number";
CA _ item data[5][ 1]= Field;
field = x509 certificate . getissuerdn()。 getName(); //Get the publisher name
CA_ItemData[6][0] = "publisher name";
CA _ item data[6][ 1]= Field;
field = x509 certificate . getsigalgname(); //get the signature algorithm
CA_ItemData[7][0] = "signature algorithm";
CA _ item data[7][ 1]= Field;
field = x509 certificate . get public key()。 getAlgorithm(); //Algorithm for obtaining public key
CA_ItemData[8][0] = "public key algorithm";
CA _ item data[8][ 1]= Field;
//Close the input stream object
file _ inputstream . close();
final JTable table = new JTable(CA _ item data,column names);
TableColumn tc = null// table column control
tc = table.getColumnModel()。 getColumn( 1); //Get the title
TC . setpreferedwidth(600); //Set the width
Panel.add (form); //Add to Layout Panel
} catch (exception exception) {
exception . printstacktrace(); //exception capture,
return- 1;
}
Returns 0;
}
//Read the binary fingerprint file
Private int Read_Bin(JPanel panel) (
Try {
file inputstream file _ inputstream = new file inputstream(CA _ Name);
data inputstream data _ inputstream = new data inputstream(
file _ inputstream);
Certification Factory Certification Factory = Certification Factory
. getInstance(" x . 509 ");
byte[]bytes = new byte[data _ inputstream . available()];
Data_inputstream.readFully (bytes);
ByteArrayInputStream bais = New ByteArrayInputStream (bytes);
JEditorPane Cert _ EditorPane
cert _ editor pane = new jeditor pane();
X509Certificate cert = null
//Traverse to get all certificate properties.
if(Bais . available()>; 0)
{
Cert = (X509Certificate) certificate factory. Generate a certificate (BAIS);
cert _ editor pane . settext(cert . tostring());
}
cert _ editor pane . disable();
JScrollPane edit _ scroll = new JScrollPane(Cert _ editor pane);
panel . add(edit _ scroll);
file _ inputstream . close();
data _ inputstream . close();
} catch (exception exception) {
exception . printstacktrace();
return- 1;
}
Returns 0;
}
Private int Read_Raw(JPanel panel) (
Try {
JEditorPane Cert _ editor pane = new JEditorPane();
string buffer strBuffer = new string buffer();
File inputFile = new file (ca _ name);
file reader in = new file reader(input file);
char[]buf = new char[2000];
int len = in.read(buf,0,2000);
for(int I = 1; I & ltleni++) {
strbuffer . append(buf[I]);
}
in . close();
cert _ editor pane . settext(strbuffer . tostring());
cert _ editor pane . disable();
JScrollPane edit _ scroll = new JScrollPane(Cert _ editor pane);
panel . add(edit _ scroll);
} catch (exception exception) {
exception . printstacktrace();
return- 1;
}
Returns 0;
}
}