E.g.
/**
* Encrypt plain text with a specific algorithm and key.
*
* @param transformation Algorithm or algorithm/mode/padding string.
* @param key SecretKey to use for encrypting.
* @param plainText Text to encrypt.
* @return Encrypted text or null if failed.
* @throws Exception
*/
static public String encrypt(String transformation, SecretKey key, String plainText) throws Exception {
String result = null;
if (transformation != null && key != null && plainText != null) {
Cipher cipher = Cipher.getInstance(transformation);
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] stringBytes = plainText.getBytes(ICConstants.ENCODING_ISO88591); //encode
byte[] rawBytes = cipher.doFinal(stringBytes); //encrypt
BASE64Encoder encoder = new BASE64Encoder();
result = encoder.encodeBuffer(rawBytes); //encode bytes to base64 to get a string
}
return result;
}//encrypt()
with "DES" as the transformation parameter.