A virtual teacher who reveals to you the great secrets of Base64

Java Base64 Decode

Since Java 1.8 developers can use the Base64.Decoder class to decode Base64 values. This class provides several methods for decoding Base64 to byte data using algorithms specified in RFC 4648 and RFC 2045. In addition, Java provides the Base64.Encoder class for encoding data to Base64.

Example #1 (decode string):

import java.util.Base64;

class Base64Decode {
  public static void main(String[] args) {
    String b64 = "Z3VydQ==";
    byte[] decoder = Base64.getDecoder().decode(b64);
    String str = new String(decoder);
    System.out.println(str); //-> "guru"
  }
}
Comments (34)

I hope you enjoy this discussion. In any case, I ask you to join it.

  • nicolas,
    Hi, for decode a PDF File its the same method?
    • Administrator,
      Hello,
      That’s right, you should use the same method, both for decoding text and for binary data. Just keep in mind that the decode() method returns a byte array. By the way, you can see a full example here: Convert Base64 to PDF in Java.
  • Gopal,
    Hi, I want to encode a Japanese language character from javascript and decode in java.

    Also in the same project, I want to encode the Japanese language character in java and decode in java.

    Means to say that I have to encode character from 2 sides there are 2 encoders one on js and other is from java but the decoder for both of them is same.

    I am using JSP and Struts2 action.

    Please help me I am just stuck in that project.

    Thanks in advance.
  • Hicham,
    "US-ASCII"
  • manoj,
    EgA1RVo5Py4=
  • Umesh,
    BADCD7C2B1D0D2FDBEDAD8C4BADCD7C5B1D0D2FDBEDAD8C56AB1D3DEC9BDD7D8C4B7DCD5F561BEDAD8DC78796E76717D6F61BEDAD8C3BADCD6FBB1D0D3C0BEDAD8CD
  • Deepak,
    How can i decrypt this this is very important to me plz reply

    Lcom/github/megatronking/stringfog/xor/StringFogImpl;->decrypt(Ljava/lang/String;)Ljava/lang/String
  • nqhXncMU,
    -1' OR 2+47-47-1=0+0+0+1 --
  • nqhXncMU,
    4khzqaZP') OR 60=(SELECT 60 FROM PG_SLEEP(15))--
  • nqhXncMU,
    -1' OR 2+513-513-1=0+0+0+1 or 'spDEE55o'='
  • nqhXncMU,
    7EAZHbPi' OR 405=(SELECT 405 FROM PG_SLEEP(15))--
  • nqhXncMU,
    if(now()=sysdate(),sleep(15),0)
  • nqhXncMU,
    555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • nqhXncMU,
    555*632*627*0
  • nqhXncMU,
    555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • nqhXncMU,
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • nqhXncMU,
    -5) OR 458=(SELECT 458 FROM PG_SLEEP(15))--
  • nqhXncMU,
    -1); waitfor delay '0:0:15' --
  • nqhXncMU,
    XQ6mkweD'; waitfor delay '0:0:15' --
  • gBqsPxAZ,
    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
  • gBqsPxAZ,
    555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • gBqsPxAZ,
    qv1qUvLd'; waitfor delay '0:0:15' --
  • gBqsPxAZ,
    0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
  • gBqsPxAZ,
    555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • nqhXncMU,
    -5 OR 712=(SELECT 712 FROM PG_SLEEP(15))--
  • nqhXncMU,
    1 waitfor delay '0:0:15' --
  • nqhXncMU,
    n0djPESF')) OR 278=(SELECT 278 FROM PG_SLEEP(15))--
  • nqhXncMU,
    -1 OR 2+649-649-1=0+0+0+1 --
  • nqhXncMU,
    -5) OR 280=(SELECT 280 FROM PG_SLEEP(15))--
  • nqhXncMU,
    -5) OR 187=(SELECT 187 FROM PG_SLEEP(15))--
  • ncMUFCMU,
    -1); waitfor delay '0:0:15' --
  • ncMUFCMU,
    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
  • ncMUFCMU,
    -1; waitfor delay '0:0:15' --
Add new comment

If you have any questions, remarks, need help, or just like this page, please feel free to let me know by leaving a comment using the form bellow.
I will be happy to read every comment and, if necessary, I will do my best to respond as quickly as possible. Of course, spammers are welcome only as readers.