JDK Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.32, 2006

JCA - Private and Public Key Pairs

Part:   1  2  3  4  

JDK Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Internationalization

Character Set and Encoding

Socket Communication

Document Object Model (DOM)

XSD Validation in Java

XSL - Transformer in Java

JCA - Private and Public Key Pairs

JCE - Secret Key

SSL (Secure Socket Layer)

SSL - Client Authentication

... Table of Contents

(Continued from previous part...)

Comparing the default implementation of DSA algorithm with RSA algorithm, the DSA implementation returns all the internal parameters of the keys in the toString() method.

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

java -cp . JcaKeyPair 512 diff DiffieHellman

KeyPairGenerator Object Info:
Algorithm = DiffieHellman
Provider = SunJCE version 1.5
Key Size = 512
toString = java.security.KeyPairGenerator$Delegate@66848c

Private Key Info:
Algorithm = DH
Saved File = diff.pri
Size = 228
Format = PKCS#8
toString = SunJCE Diffie-Hellman Private Key:
x:
0590104f 019c57c1 c6cfd079 6e7805d2 6961fea1 99d1ab50 5c5d9c1f b6859e21
2e312451 880c6727 c71010e2 f8dbb489 0d2f8f26 bea1b064 84ff5e17 0e6afa05
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:
507

Public Key Info:
Algorithm = DH
Saved File = diff.pub
Size = 226
Format = X.509
toString = SunJCE Diffie-Hellman Public Key:
y:
1d5d094c 75a3264e b65f16e1 16caeb20 5a9bde14 27d6653f da7ed69c da7c4800
df18a6d2 0314bbac 65eaed6b 5b11fc09 02a422ea ec648c67 ff70f202 4ee62444
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:
507

java -cp . HexWriter diff.pri diff_pri.hex
Number of input bytes: 228

type diff_pri.hex
3081E102010030819706092A864886F7
0D010301308189024100FCA682CE8E12
CABA26EFCCF7110E526DB078B05EDECB
CD1EB4A208F3AE1617AE01F35B91A47E
6DF63413C5E12ED0899BCD132ACD50D9
9151BDC43EE737592E170240678471B2
7A9CF44EE91A49C5147DB1A9AAF244F0
5A434D6486931D2D14271B9E35030B71
FD73DA179069B32E2935630E1C206235
4D0DA20A6C416E50BE794CA4020201FB
044202400590104F019C57C1C6CFD079
6E7805D26961FEA199D1AB505C5D9C1F
B6859E212E312451880C6727C71010E2
F8DBB4890D2F8F26BEA1B06484FF5E17
0E6AFA05

java -cp . HexWriter diff.pub diff_pub.hex
Number of input bytes: 226

type diff_pub.hex
3081DF30819706092A864886F70D0103
01308189024100FCA682CE8E12CABA26
EFCCF7110E526DB078B05EDECBCD1EB4
A208F3AE1617AE01F35B91A47E6DF634
13C5E12ED0899BCD132ACD50D99151BD
C43EE737592E170240678471B27A9CF4
4EE91A49C5147DB1A9AAF244F05A434D
6486931D2D14271B9E35030B71FD73DA
179069B32E2935630E1C2062354D0DA2
0A6C416E50BE794CA4020201FB034300
02401D5D094C75A3264EB65F16E116CA
EB205A9BDE1427D6653FDA7ED69CDA7C
4800DF18A6D20314BBAC65EAED6B5B11
FC0902A422EAEC648C67FF70F2024EE6
2444

Conclusion

  • JDK 1.5.0 supports 3 algorithms to generate private and public pairs: RSA, DSA, and DiffieHellman.

Question: Key pairs are used to encrypt and decrypt data. But how to do this? Which classes and methods to use?

Part:   1  2  3  4  

Dr. Herong Yang, updated in 2006
JDK Tutorials - Herong's Tutorial Notes - JCA - Private and Public Key Pairs