import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; /** * Section 1 *

* Short example to kick-off the book. * * @author Jason R. Weiss * @version 1.0 * */ public class DES_ECB { public static void main(String[] args) { try { KeyGenerator kg = KeyGenerator.getInstance("DES"); SecretKey key = kg.generateKey(); SecretKeySpec keySpec = new SecretKeySpec(key.getEncoded(), "DES"); Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.ENCRYPT_MODE, keySpec); String plainText = "This is a secret"; byte[] cipherText = cipher.doFinal(plainText.getBytes()); System.out.println("Resulting Cipher Text:\n"); for(int i=0;i