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.BASE64Encoder
and use Apache Commons Base64 class. Here is the link: http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.html
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.
import java.util.Base64;
Base64.getDecoder().decode(...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With