∟JcaKeyStoreTest.java - 'keystore' Class Test Program
This chapter provides tutorial notes and example codes on the 'keystore' class. Topics include the Certificate class, using the CertificateFactory class to read and write certificates; the KeyStore class; opening 'keystore' files to read and write certificates.
The following sample program shows you how to load a keystore database from a file
into a KeyStore object, extracting a certificate from the keystore into a certificate file,
then importing the certificate back into the keystore.
Here is the result of my firsts test. It uses the key store file generated from
the "keytool" command. See the previous chapter for details.
java -cp . JcaKeyStoreTest herong.jks HerongJKS my_home
KeyStore Object Info:
Type = JKS
Provider = SUN version 1.2
toString = java.security.KeyStore@6ec612
KeyStore Content:
Size = 4
my_home_2: Certificate entry
my_home: Key entry
his_home: Key entry
my_copy: Key entry
Certificate Object Info:
Type = X.509
toString = [
[
Version: V1
Subject: CN=Herong Yang, OU=My Unit, O=My Home, L=My City, ST=My...
Signature Algorithm: SHA1withDSA, OID = 1.2.840.10040.4.3
Key: Sun DSA Public Key
Parameters:DSA
...
Issuer: CN=Herong Yang, OU=My Unit, O=My Home, L=My City, ST=My ...
SerialNumber: [ 407928a4 ]
]
Algorithm: [SHA1withDSA]
Signature:
0000: 30 2C 02 14 38 CC 05 0E 3D 67 B5 C1 D8 B0 C9 EF 0,..8...=...
0010: 57 0E C5 4F 70 A4 B5 C7 02 14 59 37 68 93 A4 48 W..Op.......
0020: 79 E0 8C 44 8C AD 2B 07 13 3A 8E FF AA 93 y..D..+.....
]
CertificateFactory Object Info:
Type = X.509
Provider = SUN version 1.2
toString = java.security.cert.CertificateFactory@3ab50a
Note that the extracted certificate is imported back into the key store a new certificate entry.
You can see the new entry, my_home4, if you run the program again: