DiffieHellman Private Key and Public Key Pair Sample

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

Now let's see the private key and public key generated by the DiffieHellman algorithm:

herong> java JcaKeyPair 512 diff DiffieHellman

KeyPairGenerator Object Info:
Algorithm = DiffieHellman
Provider = SunJCE version 10
Key Size = 512
toString = java.security.KeyPairGenerator$Delegate@51565ec2

Private Key Info:
Algorithm = DH
Saved File = diff.pri
Size = 213
Format = PKCS#8
toString = com.sun.crypto.provider.DHPrivateKey@d5a2e3ff

Public Key Info:
Algorithm = DH
Saved File = diff.pub
Size = 226
Format = X.509
toString = SunJCE Diffie-Hellman Public Key:
y:
080d39af e8ce95e2 3ee5326a 63fd3995 b921a49f e3be4632 0ac157d5 8cb635d8
9f6b2d67 e87eacd9 550b9b04 f36acc25 898cd6a3 cbab8365 5932dbd7 c414ec50
p:
fca682ce 8e12caba 26efccf7 110e526d b078b05e decbcd1e b4a208f3 ae1617ae
01f35b91 a47e6df6 3413c5e1 2ed0899b cd132acd 50d99151 bdc43ee7 37592e17
g:
678471b2 7a9cf44e e91a49c5 147db1a9 aaf244f0 5a434d64 86931d2d 14271b9e
35030b71 fd73da17 9069b32e 2935630e 1c206235 4d0da20a 6c416e50 be794ca4
l:
384

herong> java HexWriter diff.pri diff_pri.hex

herong> more diff_pri.hex
3081D202010030819706092A864886F7
0D010301308189024100FCA682CE8E12
CABA26EFCCF7110E526DB078B05EDECB
CD1EB4A208F3AE1617AE01F35B91A47E
6DF63413C5E12ED0899BCD132ACD50D9
9151BDC43EE737592E170240678471B2
7A9CF44EE91A49C5147DB1A9AAF244F0
5A434D6486931D2D14271B9E35030B71
FD73DA179069B32E2935630E1C206235
4D0DA20A6C416E50BE794CA402020180
0433023100B946E13556146F1ACABADD
C8241BE4AB61E4FDE3A967AEA80FF6C7
008F2EE1039AF58B1EFC600129592285
52CC2E4AB3

herong> java -cp . HexWriter diff.pub diff_pub.hex

herong> more diff_pub.hex
3081DF30819706092A864886F70D0103
01308189024100FCA682CE8E12CABA26
EFCCF7110E526DB078B05EDECBCD1EB4
A208F3AE1617AE01F35B91A47E6DF634
13C5E12ED0899BCD132ACD50D99151BD
C43EE737592E170240678471B27A9CF4
4EE91A49C5147DB1A9AAF244F05A434D
6486931D2D14271B9E35030B71FD73DA
179069B32E2935630E1C2062354D0DA2
0A6C416E50BE794CA402020180034300
0240080D39AFE8CE95E23EE5326A63FD
3995B921A49FE3BE46320AC157D58CB6
35D89F6B2D67E87EACD9550B9B04F36A
CC25898CD6A3CBAB83655932DBD7C414
EC50

Table of Contents

 About This JDK Tutorial Book

 JDK (Java Development Kit)

 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

 Java Logging

 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

 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

 Digital Signature Algorithm and Sample Program

 "keytool" Commands and "keystore" Files

 KeyStore and Certificate Classes

 Secret Key Generation and Management

 Cipher - 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

 Full Version in PDF/EPUB