We still used sun proprietary API (sun.misc.BASE64Decoder
, sun.misc.BASE64Encoder
), which gives compilation warnings.
So someday, I decide it to the codec replacement.
- apache commons
- javax.xml.bind
- java8 BASE64 API
whitespace issue http://stackoverflow.com/questions/3092019/can-a-base64-encoded-string-contain-whitespace
No it can't. See Base64 for the allowed character repository used by base64, which are the characters A-Z, a-z, 0-9, + and / (the last two may differ depending on the implementation) as well as the padding character = (but that's also implementation dependent as some implementations don't use padding at all).
.replaceAll("\\s", "")
on the string which contains whitespace will do the work
byte[] decordedValue = Base64.getDecoder().decode(valueToDecrypt.replaceAll("\\s", ""));
On android, Use Base64.NO_WRAP
instead of Base64.DEFAULT
@Override
protected String encode(byte[] bytes) {
return Base64.encodeToString(bytes, Base64.NO_WRAP);
}