+ /**
+ * Wrap the given {@link InputStream} so it is transparently encrypted by
+ * the current {@link CryptUtils}.
+ *
+ * @param in
+ * the {@link InputStream} to wrap
+ * @return the auto-encode {@link InputStream}
+ */
+ public InputStream encrypt(InputStream in) {
+ Cipher ecipher = newCipher(Cipher.ENCRYPT_MODE);
+ return new CipherInputStream(in, ecipher);
+ }
+
+ /**
+ * Wrap the given {@link InputStream} so it is transparently encrypted by
+ * the current {@link CryptUtils} and encoded in base64.
+ *
+ * @param in
+ * the {@link InputStream} to wrap
+ * @param zip
+ * TRUE to also uncompress the data from a GZIP format; take care
+ * about this flag, as it could easily cause errors in the
+ * returned content or an {@link IOException}
+ *
+ * @return the auto-encode {@link InputStream}
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public InputStream encrypt64(InputStream in, boolean zip)
+ throws IOException {
+ return StringUtils.base64(encrypt(in), zip, false);
+ }
+
+ /**
+ * Wrap the given {@link OutputStream} so it is transparently encrypted by
+ * the current {@link CryptUtils}.
+ *
+ * @param out
+ * the {@link OutputStream} to wrap
+ *
+ * @return the auto-encode {@link OutputStream}
+ */
+ public OutputStream encrypt(OutputStream out) {
+ Cipher ecipher = newCipher(Cipher.ENCRYPT_MODE);
+ return new CipherOutputStream(out, ecipher);
+ }
+
+ /**
+ * Wrap the given {@link OutputStream} so it is transparently encrypted by
+ * the current {@link CryptUtils} and encoded in base64.
+ *
+ * @param out
+ * the {@link OutputStream} to wrap
+ * @param zip
+ * TRUE to also uncompress the data from a GZIP format; take care
+ * about this flag, as it could easily cause errors in the
+ * returned content or an {@link IOException}
+ *
+ * @return the auto-encode {@link OutputStream}
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public OutputStream encrypt64(OutputStream out, boolean zip)
+ throws IOException {
+ return encrypt(StringUtils.base64(out, zip, false));
+ }
+
+ /**
+ * Wrap the given {@link OutputStream} so it is transparently decoded by the
+ * current {@link CryptUtils}.
+ *
+ * @param in
+ * the {@link InputStream} to wrap
+ *
+ * @return the auto-decode {@link InputStream}
+ */
+ public InputStream decrypt(InputStream in) {
+ Cipher dcipher = newCipher(Cipher.DECRYPT_MODE);
+ return new CipherInputStream(in, dcipher);
+ }
+
+ /**
+ * Wrap the given {@link OutputStream} so it is transparently decoded by the
+ * current {@link CryptUtils} and decoded from base64.
+ *
+ * @param in
+ * the {@link InputStream} to wrap
+ * @param zip
+ * TRUE to also uncompress the data from a GZIP format; take care
+ * about this flag, as it could easily cause errors in the
+ * returned content or an {@link IOException}
+ *
+ * @return the auto-decode {@link InputStream}
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public InputStream decrypt64(InputStream in, boolean zip)
+ throws IOException {
+ return decrypt(StringUtils.unbase64(in, zip));
+ }
+
+ /**
+ * Wrap the given {@link OutputStream} so it is transparently decoded by the
+ * current {@link CryptUtils}.
+ *
+ * @param out
+ * the {@link OutputStream} to wrap
+ * @return the auto-decode {@link OutputStream}
+ */
+ public OutputStream decrypt(OutputStream out) {
+ Cipher dcipher = newCipher(Cipher.DECRYPT_MODE);
+ return new CipherOutputStream(out, dcipher);
+ }
+
+ /**
+ * Wrap the given {@link OutputStream} so it is transparently decoded by the
+ * current {@link CryptUtils} and decoded from base64.
+ *
+ * @param out
+ * the {@link OutputStream} to wrap
+ * @param zip
+ * TRUE to also uncompress the data from a GZIP format; take care
+ * about this flag, as it could easily cause errors in the
+ * returned content or an {@link IOException}
+ *
+ * @return the auto-decode {@link OutputStream}
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public OutputStream decrypt64(OutputStream out, boolean zip)
+ throws IOException {
+ return StringUtils.unbase64(decrypt(out), zip);
+ }
+