!1074 base64 NPE verification

Merge pull request !1074 from 蒋小小/v5-dev
This commit is contained in:
Looly
2023-09-12 10:38:17 +00:00
committed by Gitee

View File

@@ -30,6 +30,9 @@ public class Base64 {
* @return 编码后的bytes
*/
public static byte[] encode(byte[] arr, boolean lineSep) {
if (arr == null) {
return null;
}
return lineSep ?
java.util.Base64.getMimeEncoder().encode(arr) :
java.util.Base64.getEncoder().encode(arr);
@@ -137,6 +140,9 @@ public class Base64 {
* @return 被加密后的字符串
*/
public static String encode(byte[] source) {
if (source == null) {
return null;
}
return java.util.Base64.getEncoder().encodeToString(source);
}
@@ -148,6 +154,9 @@ public class Base64 {
* @since 5.5.2
*/
public static String encodeWithoutPadding(byte[] source) {
if (source == null) {
return null;
}
return java.util.Base64.getEncoder().withoutPadding().encodeToString(source);
}
@@ -159,6 +168,9 @@ public class Base64 {
* @since 3.0.6
*/
public static String encodeUrlSafe(byte[] source) {
if (source == null) {
return null;
}
return java.util.Base64.getUrlEncoder().withoutPadding().encodeToString(source);
}