Tutorial: Java Cryptography

Goal

The goal with this tutorial is to achieve some familiarity with the fundamental concepts behind the Java Cryptography Architecture and provide hands on experience with the APIs and cryptographic primitives supported in Java.

Laboratory Work

The laboratory work will take you through three classes of cryptographic primitives: cryptographic hash functions, symmetric cryptography and asymmetric cryptography (digital signatures.)

For the purpose of this exercise, you should download and use the file AandB.txt, which is an extract from "The Alice and Bob After Dinner Speech" given at the Zurich Seminar, April 1984, by John Gordon, by invitation of Professor James Massey.

Cryptographic Hash Functions

Write a simple program that calculates the cryptographic hash of the file "AandB.txt". Try to use at least two different cryptographic hash functions. A few cryptographic hash values for the files are listed in the table below.

Hash function  Hash value
MD5  3b67df8682ecb62c1630c0fa1a0c9780
SHA-1  8c3dd8944d20f60ce56d3c75158066691226ab6d
SHA-256  0bd24d6747fe70d02585697bb4e8f74dd74c27059df12f9e9c9a96127b4cc9c2

Symmetric Cryptography

Write a simple program that generates a symmetric key and encrypts the file "AandB.txt". Consider encrypting the file using different modes. Having encrypted the file, you should decrypt it again using the previously generated key and compare the decrypted file to the original file.

Asymmetric Cryptography

Generate an asymmetric key-pair and use the private key to sign one of the files that you encrypted above. Then use the public-key to verify the signature on the file. You can find information about the Java Cryptographic Architecture (JCA), which also contains a number of examples.

Useful Links


Christian Damsgaard Jensen Christian.Jensen@imm.dtu.dk
Last modified 20 September 2017.