mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add base64 check
This commit is contained in:
parent
41fbaa8073
commit
d941fa85a7
@ -24,7 +24,8 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Base64解码实现<br>
|
||||
* 此解码保留的原因是,JDK提供的解码需要指定是否为URL安全的或是否换行,此解码无需区分
|
||||
* 此解码保留的原因是,JDK提供的解码需要指定是否为URL安全的或是否换行,此解码无需区分<br>
|
||||
* 此解码对非Base64字符忽略
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
|
@ -540,7 +540,12 @@ public class SecureUtil {
|
||||
// issue#I90M9D
|
||||
// 某些特殊字符串会无法区分Hex还是Base64,此处使用系统属性强制关闭Hex解析
|
||||
final boolean decodeHex = SystemUtil.getBoolean(HUTOOL_CRYPTO_DECODE_HEX, true);
|
||||
return (decodeHex && Validator.isHex(key)) ? Hex.decode(key) : Base64.decode(key);
|
||||
if(decodeHex && Validator.isHex(key)){
|
||||
return Hex.decode(key);
|
||||
}else if(Base64.isTypeBase64(key)){
|
||||
return Base64.decode(key);
|
||||
}
|
||||
throw new IllegalArgumentException("Value is not hex or base64!");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,7 +149,8 @@ public class AESTest {
|
||||
|
||||
@Test
|
||||
void issue3766Test() {
|
||||
Assertions.assertThrows(CryptoException.class, ()->
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()->
|
||||
// data必须为hex或base64
|
||||
SecureUtil.aes("8888888888888888".getBytes()).decryptStr("哈哈"));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user