add base64 check

This commit is contained in:
Looly
2024-10-11 18:04:28 +08:00
parent 41fbaa8073
commit d941fa85a7
3 changed files with 10 additions and 3 deletions

View File

@@ -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!");
}
/**

View File

@@ -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("哈哈"));
}
}