I have the following code for sun.misc.BASE64Encoder
:
BASE64Decoder decoder = new BASE64Decoder();
byte[] saltArray = decoder.decodeBuffer(saltD);
byte[] ciphertextArray = decoder.decodeBuffer(ciphertext);
and would like to convert it to org.apache.commons.codec.binary.Base64
. I've gone through the APIs, the docs, etc., but I can't find something that seems to match and give the same resulting values.
You can use decodeBase64(byte[] base64Data) or decodeBase64(String base64String) methods. For example:
Here is a short example:
It's actually almost the exact same:
For decoding:
This last one was tougher because you use "toString" at the end.
Instead of these two class(import sun.misc.BASE64Encoder; import sun.misc.BASE64Decoder), you can use java.util.Base64 class.Now change encode and decode method as below. For encoding :
For decoding:
Here ciphertext is the encoded password in encoding method .
Now everything is done, you can save your program and run. It will run without showing any error.