Java base64 encryption code

From , 5 Years ago, written in Java, viewed 188 times.
URL https://pastebin.vip/view/ac4e7a4f
  1. import java.io.ByteArrayInputStream;
  2. import java.io.ByteArrayOutputStream;
  3. import java.io.InputStream;
  4. import java.io.OutputStream;
  5.  
  6. import javax.mail.internet.MimeUtility;
  7.  
  8. public class Base64 {
  9.  public static byte[] encode(byte[] b) throws Exception {
  10.   ByteArrayOutputStream baos = null;
  11.   OutputStream b64os = null;
  12.   try {
  13.    baos = new ByteArrayOutputStream();
  14.    b64os = MimeUtility.encode(baos, "base64");
  15.    b64os.write(b);
  16.    b64os.close();
  17.    return baos.toByteArray();
  18.   } catch (Exception e) {
  19.    throw new Exception(e);
  20.   } finally {
  21.    try {
  22.     if (baos != null) {
  23.      baos.close();
  24.      baos = null;
  25.     }
  26.    } catch (Exception e) {
  27.    }
  28.    try {
  29.     if (b64os != null) {
  30.      b64os.close();
  31.      b64os = null;
  32.     }
  33.    } catch (Exception e) {
  34.    }
  35.   }
  36.  }
  37.  
  38.  public static byte[] decode(byte[] b) throws Exception {
  39.   ByteArrayInputStream bais = null;
  40.   InputStream b64is = null;
  41.   try {
  42.    bais = new ByteArrayInputStream(b);
  43.    b64is = MimeUtility.decode(bais, "base64");
  44.    byte[] tmp = new byte[b.length];
  45.    int n = b64is.read(tmp);
  46.    byte[] res = new byte[n];
  47.    System.arraycopy(tmp, 0, res, 0, n);
  48.  
  49.    return res;
  50.   } catch (Exception e) {
  51.    throw new Exception(e);
  52.   } finally {
  53.    try {
  54.     if (bais != null) {
  55.      bais.close();
  56.      bais = null;
  57.     }
  58.    } catch (Exception e) {
  59.    }
  60.    try {
  61.     if (b64is != null) {
  62.      b64is.close();
  63.      b64is = null;
  64.     }
  65.    } catch (Exception e) {
  66.    }
  67.   }
  68.  }
  69. }
  70. //java/5679

Reply to "Java base64 encryption code"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website