import javax.crypto.SecretKey;
import javax.crypto.Cipher;
/**
* DES is a wrapper class which allows encryption/decryption using the DES block cipher
*/
public class DES {
/**
* encrypts plaintext given as a byte array
* @param ptBytes plaintext given as byte array
* @param key secret key
* @return returns byte array containing the ciphertext
*/
public static byte [] encrypt(byte[] ptBytes, SecretKey key) throws Exception
{
Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, key);
return cipher.doFinal(ptBytes);
}
/**
* decrypts ciphertext given as a byte array
* @param ctBytes ciphertext given as byte array
* @param key secret key
* @return returns byte array containing the plaintext
*/
public static byte [] decrypt(byte[] ctBytes, SecretKey key) throws Exception
{
Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, key);
return cipher.doFinal(ctBytes);
}
}