Code example for Cipher

Methods: doFinal, init

0
	 * The implementation of the cipher is black-box, so as a preventive measure, better synchronize the 
	 * en-/decryption. 
	 */ 
	 
	public synchronized byte[] encrypt(byte[] data) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
		cipher.init(Cipher.ENCRYPT_MODE, key);
		return cipher.doFinal(data);
	} 
	 
	public synchronized byte[] decrypt(byte[] data) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
		cipher.init(Cipher.DECRYPT_MODE, key);
		return cipher.doFinal(data);
	} 
}