DSA Private Key and Public Key Pair Sample

This section provides a tutorial example on how to run JcaKeyPair.java to generate a DSA private key and public key pair sample. Keys are stored PKCS#8 and X.509 encoding formats.

Here is the result of my first test of JcaKeyPair.java - generating a pair of DSA private key and public key.

herong> javac JcaKeyPair.java

herong> java JcaKeyPair 512 dsa dsa

KeyPairGenerator Object Info:
Algorithm = DSA
Provider = SUN version 12
Key Size = 512
toString = sun.security.provider.DSAKeyPairGenerator@19b49e6

Private Key Info:
Algorithm = DSA
Saved File = dsa.pri
Size = 201
Format = PKCS#8
toString = Sun DSA Private Key
parameters:
p:
fca682ce 8e12caba 26efccf7 110e526d b078b05e decbcd1e b4a208f3 ae1617ae
01f35b91 a47e6df6 3413c5e1 2ed0899b cd132acd 50d99151 bdc43ee7 37592e17
q:
962eddcc 369cba8e bb260ee6 b6a126d9 346e38c5
g:
678471b2 7a9cf44e e91a49c5 147db1a9 aaf244f0 5a434d64 86931d2d 14271b9e
35030b71 fd73da17 9069b32e 2935630e 1c206235 4d0da20a 6c416e50 be794ca4

x:     4e3ca05f 1a902b97 46f0dec2 9d70f952 8f33ee77


Public Key Info:
Algorithm = DSA
Saved File = dsa.pub
Size = 243
Format = X.509
toString = Sun DSA Public Key
Parameters:
p:
fca682ce 8e12caba 26efccf7 110e526d b078b05e decbcd1e b4a208f3 ae1617ae
01f35b91 a47e6df6 3413c5e1 2ed0899b cd132acd 50d99151 bdc43ee7 37592e17
q:
962eddcc 369cba8e bb260ee6 b6a126d9 346e38c5
g:
678471b2 7a9cf44e e91a49c5 147db1a9 aaf244f0 5a434d64 86931d2d 14271b9e
35030b71 fd73da17 9069b32e 2935630e 1c206235 4d0da20a 6c416e50 be794ca4

y:
54e3a092 862564f4 32ff94ec dcf052d2 502f2a3b d45fcb06 a53c2b9f 2224b25a
8951fe72 d7cae350 5fb307ab de5f828c a5703417 505abc51 efd2c15a 56445bfd

The program seems to be working:

In order to see the keys, I need to use my other program, HexWriter.java, to convert binary data to hex numbers. See chapter "Encoding Conversion" for details.

Here is how to look at DSA key files in hex numbers, 16 bytes per line:

herong> javac HexWriter.java

herong> java HexWriter dsa.pri dsa_pri.hex

herong> more dsa_pri.hex
3081C60201003081A806072A8648CE38
040130819C024100FCA682CE8E12CABA
26EFCCF7110E526DB078B05EDECBCD1E
B4A208F3AE1617AE01F35B91A47E6DF6
3413C5E12ED0899BCD132ACD50D99151
BDC43EE737592E17021500962EDDCC36
9CBA8EBB260EE6B6A126D9346E38C502
40678471B27A9CF44EE91A49C5147DB1
A9AAF244F05A434D6486931D2D14271B
9E35030B71FD73DA179069B32E293563
0E1C2062354D0DA20A6C416E50BE794C
A4041602144E3CA05F1A902B9746F0DE
C29D70F9528F33EE77

herong> java -cp . HexWriter dsa.pub dsa_pub.hex

herong> more dsa_pub.hex
3081F03081A806072A8648CE38040130
819C024100FCA682CE8E12CABA26EFCC
F7110E526DB078B05EDECBCD1EB4A208
F3AE1617AE01F35B91A47E6DF63413C5
E12ED0899BCD132ACD50D99151BDC43E
E737592E17021500962EDDCC369CBA8E
BB260EE6B6A126D9346E38C502406784
71B27A9CF44EE91A49C5147DB1A9AAF2
44F05A434D6486931D2D14271B9E3503
0B71FD73DA179069B32E2935630E1C20
62354D0DA20A6C416E50BE794CA40343
00024054E3A092862564F432FF94ECDC
F052D2502F2A3BD45FCB06A53C2B9F22
24B25A8951FE72D7CAE3505FB307ABDE
5F828CA5703417505ABC51EFD2C15A56
445BFD

Table of Contents

 About This Book

 Cryptography Terminology

 Cryptography Basic Concepts

 Introduction to AES (Advanced Encryption Standard)

 Introduction to DES Algorithm

 DES Algorithm - Illustrated with Java Programs

 DES Algorithm Java Implementation

 DES Algorithm - Java Implementation in JDK JCE

 DES Encryption Operation Modes

 DES in Stream Cipher Modes

 PHP Implementation of DES - mcrypt

 Blowfish - 8-Byte Block Cipher

 Secret Key Generation and Management

 Cipher - Secret Key Encryption and Decryption

 Introduction of RSA Algorithm

 RSA Implementation using java.math.BigInteger Class

 Introduction of DSA (Digital Signature Algorithm)

 Java Default Implementation of DSA

Private key and Public Key Pair Generation

 Private and Public Keys and Related Interfaces

 KeyPair and KeyPairGenerator Classes

 Key Pair Sample Program - JcaKeyPair.java

DSA Private Key and Public Key Pair Sample

 RSA Private Key and Public Key Pair Sample

 DiffieHellman Private Key and Public Key Pair Sample

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

 Cipher - Public Key Encryption and Decryption

 MD5 Mesasge Digest Algorithm

 SHA1 Mesasge Digest Algorithm

 OpenSSL Introduction and Installation

 OpenSSL Generating and Managing RSA Keys

 OpenSSL Managing Certificates

 OpenSSL Generating and Signing CSR

 OpenSSL Validating Certificate Path

 "keytool" and "keystore" from JDK

 "OpenSSL" Signing CSR Generated by "keytool"

 Migrating Keys from "keystore" to "OpenSSL" Key Files

 Certificate X.509 Standard and DER/PEM Formats

 Migrating Keys from "OpenSSL" Key Files to "keystore"

 Using Certificates in IE

 Using Certificates in Google Chrome

 Using Certificates in Firefox

 Archived Tutorials

 References

 Full Version in PDF/EPUB