Encryption by Example: Simple Java Programs

by J. Orlin Grabbe


In order to understand encryption, you have to be able to do it yourself: to see the input numbers, text, etc., and the encryption output.

Getting to that stage is often frustrating, even if you know something about a given programming language, and something about the theoretical encryption process. So maybe these pages will help you get started, using an open-source language, Java, and an open-source encryption toolkit, Cryptix.

First: Install Java

The first thing to do is get Java off the web for free. The programs here were compiled with Java version 1.1.7b. (I haven't had sufficient experience with later versions to feel confident about using them.)

To download your own copy of the Java programming language (1.1.7b) and operating system, click below:

http://java.sun.com/products/jdk/1.1.7B/

If you are using Windows, be sure to insert a PATH command in the AUTOEXEC.BAT file to the Java directory, and to the directory where you will be compiling your sample encryption program. So if you install Java in the directory c:\jdk1.1.7b and your Java programs in c:\jdk1.1.7b\practice, your path command will look like this:

set PATH=%PATH%;c:\jdk1.1.7b;c:\jdk1.1.7b\practice;

Second: Install the Cryptix Class Library

Go to the location below to get the Cryptix class library (binary), version 3.1.1:

http://www.cryptix.org/products/cryptix31/index.html

After you have unzipped the Cryptix class files and documentation, you will need to add a CLASSPATH command to the Windows AUTOEXEC.BAT file (see the Cryptix documentation for Unix, or for both Windows and Unix if you wish to compile your own binaries directly from the Cryptix source files). The classpath will need to identify the location of the Cryptix Jar files (a Jar file is the Java equivalent of a Zip file), as well as the location of the Java class files (including the ones you create yourself). Something like the following:

set CLASSPATH=%CLASSPATH%;c:\jdk1.1.7b;c:\jdk1.1.7b\practice;
set CLASSPATH=%CLASSPATH%;c:\cryptix\classes\SPT_0-1-1.jar;c:\cryptix\classes\TOOLS_0-1-1.jar;
set CLASSPATH=%CLASSPATH%;c:\cyptix\classes\ALG_0-1-1.jar;c:\cryptix\classes\RSA_0-1-1.jar;
set CLASSPATH=%CLASSPATH%;c:\cryptix\classes\ELGAMAL_0-1-1.jar;c:\cryptix\classes\IJCE_0-1-1.jar;

Third: Install Cryptix as a Java Security Provider

You will need to execute a Java command to install Cryptix as one of the Java security providers. To do this from a DOS command line, type and execute:

java cryptix.provider.Install

Okay. You are now ready to compile and run the sample programs.


To run the programs, copy them as a text file into your practice directory (c:\jdk1.1.7b\practice). For example, for a program called encryption.java, which uses an input text file called data, first execute the following from the DOS command line:

javac encryption.java

The Java compiler will compile the program and produce encryption.class.

Next execute the following from the DOS command line:

java encryption data

This will execute the encryption.class program, using data as the input file to be encrypted.

Of course, you can save time by putting both commands back-to-back in a Windows batch file, if you are going to be altering the Java program and/or data input file frequently.


Java Encryption Programs Menu

  • DES
  • Triple DES, Program 1
  • Triple DES, Program 2
  • Triple DES with Cipher Block Chaining, Program 1
  • Triple DES with Cipher Block Chaining, Program 2
  • Message Digests
  • RSA Signature and Calculations
  • Digital Signature Algorithm (DSA) and Calculations

  • This material is part of a work in progress. ©1998-2000 J. Orlin Grabbe. All Rights Reserved.

    J. Orlin Grabbe is the author of International Financial Markets, and is an internationally recognized derivatives expert who has recently branched out into cryptology, banking security, and digital cash. His home page is located at http://www.aci.net/kalliste/. He currently resides in Costa Rica.



    Return to Home Page