EncodeUtils base64 string 健壮代码
This commit is contained in:
@@ -67,6 +67,9 @@ public class EncodeUtils {
|
|||||||
* Base64编码.
|
* Base64编码.
|
||||||
*/
|
*/
|
||||||
public static String encodeBase64(String input) {
|
public static String encodeBase64(String input) {
|
||||||
|
if (StringUtils.isBlank(input)){
|
||||||
|
return StringUtils.EMPTY;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return new String(Base64.encodeBase64(input.getBytes(DEFAULT_URL_ENCODING)));
|
return new String(Base64.encodeBase64(input.getBytes(DEFAULT_URL_ENCODING)));
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
@@ -92,10 +95,13 @@ public class EncodeUtils {
|
|||||||
* Base64解码.
|
* Base64解码.
|
||||||
*/
|
*/
|
||||||
public static String decodeBase64String(String input) {
|
public static String decodeBase64String(String input) {
|
||||||
|
if (StringUtils.isBlank(input)){
|
||||||
|
return StringUtils.EMPTY;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return new String(Base64.decodeBase64(input.getBytes()), DEFAULT_URL_ENCODING);
|
return new String(Base64.decodeBase64(input.getBytes()), DEFAULT_URL_ENCODING);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
return "";
|
return StringUtils.EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user