

So your data is safe and secure with you only. And it’s very secure as we don’t share that data with our server or any server for that matter. Simple isn’t it? By the way, the URL I showed you is our simple and fast online tool to encode and decode text in Base64.
#Base64 encoding in java code
output: Code language: HTML, XML ( xml ) String originalUrl = new String ( urlDecodedByteArray ) encodedUrl = aHR0cHM6Ly93d3cuY29kZXJzdGVhLmNvbS90b29scy9iYXNlLTY0LWVuY29kZS1kZWNvZGUucGhwīyte urlDecodedByteArray = code ( encodedUrl ) An example is as follows.īase64.Decoder urlDecoder = Base64. This simple encoding only generates the string containing characters A-Za-z0-9+/ only. All types of Base64 encoders are using the same methods and class, just their types differ. Then we can use encode methods available in the class. This will give us the Encoder class for simple Base64 encoding. To encode a string to base64 in java we have to use the getEncoder() function from the Base64 class. Now let us look at the encoding and decoding of various types of data in Java one by one. For simple Base64 value use getDecoder(), in case of URL encoded text use getUrlDecoder() and lastly getMimeDecoder() for MIME-encoded data.


Similar to Base64.Encoder class, we have three different types of it. You want to read the original text at some point, right? Then what you have to do is simply decode the Base64 code to its original form. So we can use the encodeToString() method to get the encoded data into the string format. These encoding methods will return to us the encoded data in a byte array. Don’t worry, we just have to call getBytes() of the String you wish as input. After getting the Encoder, we will have to use encode() function which takes the byte array as a parameter. Use getEncoder() for simple, getUrlEncoder() for URL and getMimeEncoder() for MIME type data. To get this class you have to use static functions from the Base64 class. Java Base64 encoding is done by static Base64.Encoder class. We will look at them with both encoding and decoding code. One is simple or normal Base64, another is for URL and the third one is for MIME-friendly data. There are three different types of Base64 encoding and decoding techniques in Java. In this Base64 class, we have the static encoder and decoder methods. You can use Java Base64 via the util package. As I said you don’t need any additional library to work on Base64 in Java.
