

("String decoded is:"+ds) Īn encoded and decoded result of a string gets printed on executing the code. String s = enc.encodeToString("EduCBA".getBytes()) An IllegalArgumentException will be thrown if the input string is not in a valid format of Base64.Here, str is the input string that has to be decoded.Execution of this method will create an effect of executing the method decode( src.getBytes ( StandardCharsets.ISO_8859_1 ) ).Input string which is in the Base64 format, will be decoded with the help of the Base64 encoding scheme.("Array decoded is:"+ds) Īn encoded and decoded result of an array gets printed on executing the code. String ds = new String(dec.decode(arr2)) ("Array encoded is: "+ arr2) īase64.Decoder dec = Base64.getDecoder() An IllegalArgumentException will be thrown if the input byte array is not in a valid format of Base64.īase64.Encoder enc = Base64.getEncoder().Here, arr is the input byte array that has to be decoded.The byte array returned will be having a length similar to the resulting bytes.Results will be written into a newly allocated byte array.

Decodes each and every byte from the input array with the help of the Base64 encoding scheme.Print the result available in the decoder array.įollowing are the different methods of Java Base64 decode.Decode the encoded data using the method decode().To decode the data, create a decoder object, and create another array for storing decoded data.Once it is done, create a new array for the encoded data.It can be done using the method Base64.getEncoder(). First, create an encoder object and encode the string/ bytes/ bytebuffer based on the requirement.
