Java Base64 Decode decodeBase64(String base64Data)

Here you can find the source of decodeBase64(String base64Data)

Description

decode Base

License

Apache License

Declaration

public static byte[] decodeBase64(String base64Data) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import sun.misc.BASE64Decoder;

import java.io.*;

public class Main {
    public static byte[] decodeBase64(String base64Data) {
        try {/*from  ww  w  . j a v a2s. c o  m*/
            return new BASE64Decoder().decodeBuffer(base64Pad(base64Data));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Pads a given String s to be usable for BASE64Decoder (if it isn't padded the resulting deoceded data may be wrong)
     * @param s
     * @return
     */
    public static String base64Pad(String s) {
        int toPad = s.length() % 4;
        for (int i = 0; i < toPad; ++i) {
            s = s + "=";
        }

        return s;
    }
}

Related

  1. decode(String base64)
  2. decode(String base64Code)
  3. decodeBase64(char[] data)
  4. decodeBASE64(InputStream in, OutputStream out)
  5. decodeBase64(InputStream is, OutputStream os)
  6. decodeBase64(String data)
  7. decodeBase64(String data)
  8. decodeBASE64(String pEncoded)
  9. decodeBase64(String str)