A Simple Secure Communication using Java


We begin with the creation of the key-pair for Alice.
/export/home/siegel/keytool%keytool -genkey -alias alice -keyalg RSA -validity 180 -keystore alicesstore
Enter keystore password: goaskalice
What is your first and last name?
  [Unknown]: Alice Liddle
What is the name of your organizational unit?
  [Unknown]: Llandudno
What is the name of your organization?
  [Unknown]: W and C sea foods.
What is the name of your City or Locality?
  [Unknown]: GB
What is the name of your State or Province?
  [Unknown]:
What is the two-letter country code for this unit?
  [Unknown]: EN
Is CN=Alice Liddle, OU=Llandudno, O=W and C sea foods., L=GB, ST=Unknown, C=EN correct?
   [no]: yes

Enter key password for <alice>
   (RETURN if same as keystore password):
Now we export the certificate for use by Bob

/export/home/siegel/keytool%keytool -export -alias alice -keystore alicesstore -rfc -file alice.cer
Enter keystore password: goaskalice
Certificate stored in file <alice.cer>
Next Bob's key-pair

/export/home/siegel/keytool%keytool -genkey -alias bob -keyalg RSA -validity 180 -keystore bobsstore
Enter keystore password: bobsyouruncle
What is your first and last name?
  [Unknown]: Bob White
What is the name of your organizational unit?
  [Unknown]: ENest
What is the name of your organization?
  [Unknown]: BOF inc.
What is the name of your City or Locality?
  [Unknown]: St. Louis
What is the name of your State or Province?
  [Unknown]: MO
What is the two-letter country code for this unit?
  [Unknown]: US
Is CN=Bob White, OU=ENest, O=BOF inc., L=St. Louis, ST=MO, C=US correct?
[no]: yes

Enter key password for <bob>
(RETURN if same as keystore password):
Get his certificate for Alice.

/export/home/siegel/keytool%keytool -export -alias bob -keystore bobsstore -rfc -file bobs.cer
Enter keystore password: bobsyouruncle Certificate stored in file <bobs.cer>
For simplicity we are doing all this on one machine. In fact the keystores would be on different systems and we would somehow have to move the certificates securely.

We are now importing Bob's certificate into Alice's store and then Alice's into Bob's store.



/export/home/siegel/keytool%keytool -import -alias bobscer -keystore alicesstore -file bobs.cer
Enter keystore password: goaskalice
Owner: CN=Bob White, OU=ENest, O=BOF inc., L=St. Louis, ST=MO, C=US
Issuer: CN=Bob White, OU=ENest, O=BOF inc., L=St. Louis, ST=MO, C=US
Serial number: 3ff34caf
Valid from: Wed Dec 31 16:24:47 CST 2003 until: Mon Jun 28 17:24:47 CDT 2004
Certificate fingerprints:
   MD5: 8A:07:02:42:73:B6:B3:CC:C4:06:0E:07:97:4B:07:F0
   SHA1: 3F:AB:6B:CF:C5:35:42:9B:B5:4F:A5:88:10:A5:32:F4:D1:63:39:2B
Trust this certificate? [no]: yes
Certificate was added to keystore


/export/home/siegel/keytool%keytool -import -alias alicescer -keystore bobsstore -file alice.cer
Enter keystore password: bobsyouruncle
Owner: CN=Alice Liddle, OU=Llandudno, O=W and C sea foods., L=GB, ST=Unknown, C=EN
Issuer: CN=Alice Liddle, OU=Llandudno, O=W and C sea foods., L=GB, ST=Unknown, C=EN
Serial number: 3ff34b53
Valid from: Wed Dec 31 16:18:59 CST 2003 until: Mon Jun 28 17:18:59 CDT 2004
Certificate fingerprints:
   MD5: 89:AD:4B:E0:92:7E:F9:7C:84:2F:5A:F6:D8:85:2E:5B
   SHA1: A0:B8:59:9D:E3:27:73:AB:DD:DA:AA:08:E8:8B:59:E7:DB:2A:CE:17
Trust this certificate? [no]: yes
Certificate was added to keystore
/export/home/siegel/keytool%


Now the code. Remember that Alice is going to send a message to Bob so he is the "Server"