Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatatypeConverter vs Base64

I am currently working on a project which need 64-bit decoding after some research I found these two methods in java itself,

from JAVA 8

import java.util.Base64;

byte[] decodedBytes = Base64.getDecoder().decode("encodedUserPassword");

from JAVA 6

import javax.xml.bind.DatatypeConverter;

byte[] decodedBytes = DatatypeConverter.parseBase64Binary("encodedUserPassword");

What I want to know is why was there a need for Base64 if DatatypeConverter was already present?

Is there a different performance wise?

like image 628
Abhishek Patil Avatar asked Jul 25 '16 09:07

Abhishek Patil


1 Answers

The entire javax.xml.bind module is deprecated (even removed) on Java9 https://docs.oracle.com/javase/9/docs/api/java.xml.bind-summary.html

If your projects are using Java8 onward, then cease using that package and use instead Java8's Base64 class, so that future Java upgrades won't affect them.

On the other hand, if you must keep compatibility with Java7 or prior, you can't use Base64 (as it was introduced on Java8). For that, you should either keep using DatatypeConverter or, even better, another standalone library to encode/decode in base 64 (such as Apache Commons 64 )

like image 166
DanielCuadra Avatar answered Oct 30 '22 05:10

DanielCuadra