Code example for PBEParameterSpec

0
	/** 
	 * Initializes the Cipher for use. 
	 */ 
	public static void initCipher(Cipher cipher, int mode, SecretKey secretKey, byte[] salt, int iterationCount) {
		try { 
			cipher.init(mode, secretKey, new PBEParameterSpec(salt, iterationCount));
		} catch (InvalidKeyException e) {
			throw new IllegalArgumentException("Unable to initialize due to invalid secret key", e);			
		} catch (InvalidAlgorithmParameterException e) {
			throw new IllegalStateException("Unable to initialize due to invalid decryption parameter spec", e);
		} 
	} 
 
	/** 
	 * Invokes the Cipher to perform encryption or decryption (depending on the initialized mode). 
	 */ 
	public static byte[] doFinal(Cipher cipher, byte[] input) {
		try { 
			return cipher.doFinal(input);
		} catch (IllegalBlockSizeException e) {
			throw new IllegalStateException("Unable to invoke Cipher due to illegal block size", e);