170 likes | 357 Views
JCA, Cryptography for Java Programmer. Shawn Shuang Zhang CS 627. Cryptography Users. Application. End User. PGP, SSL. Integration. Programmer. ?. Development. Cryptographer. Math, SPI. JCA. Figure 1-1. [1] Page 30 Figure 3-1. JCE. Java Cryptography Extension. Providers.
E N D
JCA, Cryptography for Java Programmer Shawn Shuang Zhang CS 627
Cryptography Users Application End User PGP, SSL Integration Programmer ? Development Cryptographer Math, SPI
JCA Figure 1-1. [1] Page 30 Figure 3-1
JCE • Java Cryptography Extension
Providers • Cipher API • Cipher SPI
SunJCE • RSA • DES • Triple DES • MD5 • SHA-1 • Hmac with MD5 • Hamc with SHA-1
Cryptix • LIKI91 • Triple DES • DES2X • DESX • IDEA • RC2 • RC4 • Blowfish • CAST5 • SPEED • SQUARE
IAIK-ICE • RSA • Triple DES • IDEA • RC2 • RC4 • MD2 • MD5 • SHA-1 • Hmac with MD5 • Hmac with SHA-1 • CAST5 • GOST
Example • Get a Cipher • Public static Cipher getInstance(String algorithm, String provider) throws NoSuchAlgorithmException • Cipher cipher=Cipher.getInstance(“DEC”)
Initialize a Cipher • ENCRYPT_MODE • DECRYPT_MODE • Public final void init(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException • Cipher.init(Cipher.ENCRYPT_MODE, Key);
Feed the data • Public final byte[] update(byte[] input) throws IllegalStateException • Byte[] ciphertext=cipher.update(plaintext)
doFinal • Public final byte[] doFinal() IllegalStateException, IllegalBlockSizeException, BadpaddingExceptioin • Byte[] ciphertext=cipher.doFinal();
Example Cipher cipher=Cipher.getInstance(“DES/CBC/PKCS5Padding”); cipher.init(Cipher.ENCRYPT_MODE, key); Byte[] palintext=“plain”.getBytes(); Byte[] step=cipher.update(plaintext); Byte[] ciphertext=cipher.doFinal(plaintext);
References • Java Cryptography by Jonathan Knudsen • Internet Cryptography by Richard E. Smith • http://java.sun.com/products/jsk/1.4/jce • http://www.systemics.com/software/cryptix-java • http://wwwjce.iaik.tu-graz.ac.at/