+ /**
+ * 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
+ *
+ * @return the auto-encode {@link InputStream}
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public InputStream encrypt64(InputStream in) throws IOException {
+ return new Base64InputStream(encrypt(in), true);
+ }
+
+ /**
+ * 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
+ *
+ * @return the auto-encode {@link OutputStream}
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public OutputStream encrypt64(OutputStream out) throws IOException {
+ return encrypt(new Base64OutputStream(out, true));
+ }
+
+ /**
+ * 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
+ *
+ * @return the auto-decode {@link InputStream}
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public InputStream decrypt64(InputStream in) throws IOException {
+ return decrypt(new Base64InputStream(in, false));
+ }
+
+ /**
+ * 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
+ *
+ * @return the auto-decode {@link OutputStream}
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public OutputStream decrypt64(OutputStream out) throws IOException {
+ return new Base64OutputStream(decrypt(out), false);
+ }
+