Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is the sun.misc package still available in java? [duplicate]

I would like to use the Base64 encoder of the package sun.misc.BASE64Encoder because I need to encode a password. However an error is being generated when I type in the import for this package.

the message where the code for the encoder is to be used is the following:

private synchronized static String hash(final String username, final String password) {
        DIGEST.reset();
        return new BASE64Encoder().encode(DIGEST.digest((username.toLowerCase() + password).getBytes()));
    }

Is there an equivalent class in java which does the same thing? Or maybe, does someone know how to be able to get the code of the original class maybe please?

thanks :)

like image 259
ict1991 Avatar asked Dec 26 '11 21:12

ict1991


1 Answers

I suggest you forget about the sun.misc.BASE64Encoder and use Apache Commons Base64 class. Here is the link: http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.html


Update (6/7/2017)

Using sun.misc.BASE64Encoder will cause a compilation error with Java 9 and it is already giving a warning in Java 8.

The right class to use is Base64 in java.util package.

Example:

import java.util.Base64;

Base64.getDecoder().decode(...);
like image 136
DejanLekic Avatar answered Oct 03 '22 00:10

DejanLekic