Browse Source

add method

Looly 5 years ago
parent
commit
162c080e5a

+ 1 - 0
CHANGELOG.md

@@ -15,6 +15,7 @@
 * 【core   】     AnnotationUtil增加setValue方法(pr#1250@Github)
 * 【core   】     ZipUtil增加get方法
 * 【cache  】     对CacheObj等变量使用volatile关键字
+* 【core   】     Base64增加encodeWithoutPadding方法(issue#I26J16@Gitee)
 
 ### Bug修复
 * 【cron   】     修复CronTimer可能死循环的问题(issue#1224@Github)

+ 23 - 54
hutool-core/src/main/java/cn/hutool/core/codec/Base64.java

@@ -3,6 +3,7 @@ package cn.hutool.core.codec;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.util.CharsetUtil;
+import cn.hutool.core.util.StrUtil;
 
 import java.io.File;
 import java.io.InputStream;
@@ -76,6 +77,17 @@ public class Base64 {
 	}
 
 	/**
+	 * base64编码,不进行padding(末尾不会填充'=')
+	 *
+	 * @param source 被编码的base64字符串
+	 * @return 被加密后的字符串
+	 * @since 5.5.2
+	 */
+	public static String encodeWithoutPadding(CharSequence source, String charset) {
+		return encodeWithoutPadding(StrUtil.bytes(source, charset));
+	}
+
+	/**
 	 * base64编码,URL安全
 	 * 
 	 * @param source 被编码的base64字符串
@@ -121,6 +133,17 @@ public class Base64 {
 	}
 
 	/**
+	 * base64编码,不进行padding(末尾不会填充'=')
+	 *
+	 * @param source 被编码的base64字符串
+	 * @return 被加密后的字符串
+	 * @since 5.5.2
+	 */
+	public static String encodeWithoutPadding(byte[] source) {
+		return java.util.Base64.getEncoder().withoutPadding().encodeToString(source);
+	}
+
+	/**
 	 * base64编码,URL安全的
 	 * 
 	 * @param source 被编码的base64字符串
@@ -176,60 +199,6 @@ public class Base64 {
 	}
 
 	/**
-	 * base64编码
-	 * 
-	 * @param source 被编码的base64字符串
-	 * @param charset 字符集
-	 * @return 被加密后的字符串
-	 * @deprecated 编码参数无意义,作废
-	 */
-	@Deprecated
-	public static String encode(byte[] source, String charset) {
-		return Base64Encoder.encode(source);
-	}
-
-	/**
-	 * base64编码,URL安全的
-	 * 
-	 * @param source 被编码的base64字符串
-	 * @param charset 字符集
-	 * @return 被加密后的字符串
-	 * @since 3.0.6
-	 * @deprecated 编码参数无意义,作废
-	 */
-	@Deprecated
-	public static String encodeUrlSafe(byte[] source, String charset) {
-		return Base64Encoder.encodeUrlSafe(source);
-	}
-
-	/**
-	 * base64编码
-	 * 
-	 * @param source 被编码的base64字符串
-	 * @param charset 字符集
-	 * @return 被加密后的字符串
-	 * @deprecated 编码参数无意义,作废
-	 */
-	@Deprecated
-	public static String encode(byte[] source, Charset charset) {
-		return Base64Encoder.encode(source);
-	}
-
-	/**
-	 * base64编码,URL安全的
-	 * 
-	 * @param source 被编码的base64字符串
-	 * @param charset 字符集
-	 * @return 被加密后的字符串
-	 * @since 3.0.6
-	 * @deprecated 编码参数无意义,作废
-	 */
-	@Deprecated
-	public static String encodeUrlSafe(byte[] source, Charset charset) {
-		return Base64Encoder.encodeUrlSafe(source);
-	}
-
-	/**
 	 * 编码为Base64<br>
 	 * 如果isMultiLine为<code>true</code>,则每76个字符一个换行符,否则在一行显示
 	 * 

+ 1 - 1
hutool-crypto/src/main/java/cn/hutool/crypto/digest/BCrypt.java

@@ -179,7 +179,7 @@ public class BCrypt {
 	private static byte char64(char x) {
 		if ((int) x > index_64.length)
 			return -1;
-		return index_64[(int) x];
+		return index_64[x];
 	}
 
 	/**