Reading and Writing Certificates in DER and RFC Formats

This section provides test results of using my JcaCertificateTest.java program to read in certificates in DER and RFC formats. Those certificates are generated with the 'keytool' command tool.

Here is the result of my first test of my JcaCertificateTest.java program. This test requires the certificate file generated by the "keytool" command described in the previous chapter. This test is done with JDK 1.8.

>java -cp . JcaCertificateTest my_home.crt temp.crt

CertificateFactory Object Info:
Type = X.509
Provider = SUN version 1.8
toString = java.security.cert.CertificateFactory@7f5ea7

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
        p:     fd7f5381 1d751229 52df4a9c 2eece4e7 f611b752 3cef44...
    455d4022 51fb593d 8d58fabf c5f5ba30 f6cb9b55 6cd7813b 801d346f...
    6b9950a5 a49f9fe8 047b1022 c24fbba9 d7feb7c6 1bf83b57 e7c6a8a6...
    83f6d3c5 1ec30235 54135a16 9132f675 f3ae2b61 d72aeff2 2203199d...
        q:     9760508f 15230bcc b292b982 a2eb840b f0581cf5
        g:     f7e1a085 d69b3dde cbbcab5c 36b857b9 7994afbb fa3aea...
    5159578e bad4594f e6710710 8180b449 167123e8 4c281613 b7cf0932...
    3c167a8b 547c8d28 e0a3ae1e 2bb3a675 916ea37f 0bfa2135 62f1fb62...
    cca4f1be a8519089 a883dfe1 5ae59f06 928b665e 807b5525 64014c3b...

  y:
    9750b0c9 487f59e1 e13fc766 f55e96db 2b4c6103 d75f0290 6424893b...
    ca0cb9dc e2f0ad22 beea9b49 a573fcb4 f327f581 552777a2 809acc4d...
    78d16462 60ce96a3 28f74f81 fbdcb10a 2c3c9a29 33cf0a40 f541e358...
    9de5f594 24367988 0353fa09 1478dc47 8099d4d4 94af32e9 1593b2b3...

  Validity: [From: Sat Jun 1 07:14:44 EDT 2002,
               To: Sat Aug 31 07:14:44 EDT 2002]
  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..+.....

]

PublicKey Object Info:
Algorithm = DSA
Format = X.509
toString = Sun DSA Public Key
    Parameters:DSA
        p:     fd7f5381 1d751229 52df4a9c 2eece4e7 f611b752 3cef44...
    455d4022 51fb593d 8d58fabf c5f5ba30 f6cb9b55 6cd7813b 801d346f...
    6b9950a5 a49f9fe8 047b1022 c24fbba9 d7feb7c6 1bf83b57 e7c6a8a6...
    83f6d3c5 1ec30235 54135a16 9132f675 f3ae2b61 d72aeff2 2203199d...
        q:     9760508f 15230bcc b292b982 a2eb840b f0581cf5
        g:     f7e1a085 d69b3dde cbbcab5c 36b857b9 7994afbb fa3aea...
    5159578e bad4594f e6710710 8180b449 167123e8 4c281613 b7cf0932...
    3c167a8b 547c8d28 e0a3ae1e 2bb3a675 916ea37f 0bfa2135 62f1fb62...
    cca4f1be a8519089 a883dfe1 5ae59f06 928b665e 807b5525 64014c3b...

  y:
    9750b0c9 487f59e1 e13fc766 f55e96db 2b4c6103 d75f0290 6424893b...
    ca0cb9dc e2f0ad22 beea9b49 a573fcb4 f327f581 552777a2 809acc4d...
    78d16462 60ce96a3 28f74f81 fbdcb10a 2c3c9a29 33cf0a40 f541e358...
    9de5f594 24367988 0353fa09 1478dc47 8099d4d4 94af32e9 1593b2b3...

The result looks very good:

The program can also be used to read in certificate files written in printable format (RFC). Assuming my_home.rfc is a certificate file created by "keytool" in RFC format, the following command will read in the certificate in my_home.rfc without any problem:

>java -cp . JcaCertificateTest my_home.rfc temp.crt

Last update: 2014.

Table of Contents

 About This JDK Tutorial Book

 Downloading and Installing JDK 1.8.0 on Windows

 Downloading and Installing JDK 1.7.0 on Windows

 Downloading and Installing JDK 1.6.2 on Windows

 Java Date-Time API

 Date, Time and Calendar Classes

 Date and Time Object and String Conversion

 Number Object and Numeric String Conversion

 Locales, Localization Methods and Resource Bundles

 Calling and Importing Classes Defined in Unnamed Packages

 HashSet, Vector, HashMap and Collection Classes

 Character Set Encoding Classes and Methods

 Character Set Encoding Maps

 Encoding Conversion Programs for Encoded Text Files

 Socket Network Communication

 Datagram Network Communication

 DOM (Document Object Model) - API for XML Files

 SAX (Simple API for XML)

 DTD (Document Type Definition) - XML Validation

 XSD (XML Schema Definition) - XML Validation

 XSL (Extensible Stylesheet Language)

 Message Digest Algorithm Implementations in JDK

 Private key and Public Key Pair Generation

 PKCS#8/X.509 Private/Public Encoding Standards

 Digital Signature Algorithm and Sample Program

 "keytool" Commands and "keystore" Files

KeyStore and Certificate Classes

 java.security.cert.Certificate - The Certificate Class

 Using CertificateFactory Class to Read in Certificates

Reading and Writing Certificates in DER and RFC Formats

 java.security.KeyStore - The 'keystore' Class

 JcaKeyStoreTest.java - 'keystore' Class Test Program

 Secret Key Generation and Management

 Cipher - Secret Key Encryption and Decryption

 The SSL (Secure Socket Layer) Protocol

 SSL Socket Communication Testing Programs

 SSL Client Authentication

 HTTPS (Hypertext Transfer Protocol Secure)

 Outdated Tutorials

 References

 PDF Printing Version