最近在業務場景中,需要對第三方傳遞進來的字符進行base64解密,根據第三方文檔提供的解析工具,對數據進行了解析,關於Base64的解析方式如下:
String sign = "xxxxxxxxxxxxxxxxxxxxxxxx"; sun.misc.BASE64Decoder decode = new sun.misc.BASE64Decoder(); String json = new String(decode.decodeBuffer(sign));
使用sun.misc.BASE64Decoder對數據解析,放測試環境測試發現解析出來的字符串正確無誤,
但是在上線之后,根據第三方傳遞的sign,解析出來之后發現字符串最后多了一個字符 “7”,查詢邏輯 沒有發現問題,最后猜測是sun.misc.BASE64Decoder出了問題,於是換了Base64的解析jira,使用如下代碼解析:
String sign = "xxxxxxxxxxxxxxxxxxxxxxxxx"; Base64 base64 = new Base64(); String json = new String (base64.decodeBase64(sign.getBytes()));
發現返回json中數據正常,問題解決。