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 🙂
I suggest you forget about the
sun.misc.BASE64Encoderand use Apache Commons Base64 class. Here is the link: http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.htmlUpdate (6/7/2017)
Using
sun.misc.BASE64Encoderwill cause a compilation error with Java 9 and it is already giving a warning in Java 8.The right class to use is
Base64injava.utilpackage.Example: