Code example for CipherOutputStream

0
                 
            encrypt = Cipher.getInstance("AES/CBC/PKCS5Padding");
            encrypt.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
             
            out.write(iv, 0, AES.IV_SIZE); // Write out the initialization vector as the first 16 bytes.]
            return new CipherOutputStream(out, encrypt);
        } 
        catch (InvalidKeyException e) {
            throw new EncryptionException("Unable to encrypt data using key " + key,e);
        } 
        catch (NoSuchAlgorithmException e) {
            throw new EncryptionException("Unable to encrypt data using key " + key,e);
        } 
        catch (NoSuchPaddingException e) {
            throw new EncryptionException("Unable to encrypt data using key " + key,e);
        } 
        catch (InvalidAlgorithmParameterException e) {
            throw new EncryptionException("Unable to encrypt data using key " + key,e);
        } 
        catch (IOException e) {
            throw new EncryptionException("Unable to encrypt data using key " + key,e);