protected static byte[] encrypt(byte[] data, Algorithm algorithm,
			SecretKey secretKey, byte[] iv) throws JironException {

		Cipher cipher;
		try {
			cipher = Cipher.getInstance(algorithm.transformation);
		} catch (NoSuchAlgorithmException e) {
			throw new JironException("Encryption algorithm "
					+ algorithm.transformation + " not found", e);
		} catch (NoSuchPaddingException e) {
			throw new JironException("Cannot work with padding given by "
					+ algorithm.transformation, e);
		}

		try {
			cipher.init(Cipher.ENCRYPT_MODE, secretKey, new IvParameterSpec(iv));
		} catch (InvalidKeyException e) {
			throw new JironException("Key " + secretKey.toString()
					+ " is invalid", e);
		} catch (InvalidAlgorithmParameterException e) {
			throw new JironException(
					"Initialization vector passed to cipher initialization", e);
		}

		try {
			return cipher.doFinal(data); // encrypted;
		} catch (IllegalBlockSizeException e) {
			throw new JironException("Illegal block size when decrypting", e);
		} catch (BadPaddingException e) {
			throw new JironException("Bad padding when decrypting", e);
		}
	}