add method

This commit is contained in:
Looly 2020-11-26 14:42:13 +08:00
parent 4cc276e665
commit 162c080e5a
3 changed files with 25 additions and 55 deletions

View File

@ -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

View File

@ -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;
@ -75,6 +76,17 @@ public class Base64 {
return encode(source, CharsetUtil.charset(charset));
}
/**
* 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安全
*
@ -120,6 +132,17 @@ public class Base64 {
return Base64Encoder.encode(source);
}
/**
* 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安全的
*
@ -175,60 +198,6 @@ public class Base64 {
return Base64Encoder.encodeUrlSafe(FileUtil.readBytes(file));
}
/**
* 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个字符一个换行符否则在一行显示

View File

@ -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];
}
/**