mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add null check
This commit is contained in:
parent
556c728389
commit
055c9b6bd6
@ -3,13 +3,14 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.5.2 (2020-11-18)
|
# 5.5.2 (2020-11-19)
|
||||||
|
|
||||||
### 新特性
|
### 新特性
|
||||||
* 【crypto 】 KeyUtil增加重载,AES构造增加重载(issue#I25NNZ@Gitee)
|
* 【crypto 】 KeyUtil增加重载,AES构造增加重载(issue#I25NNZ@Gitee)
|
||||||
* 【json 】 JSONUtil增加toList重载(issue#1228@Github)
|
* 【json 】 JSONUtil增加toList重载(issue#1228@Github)
|
||||||
* 【core 】 新增CollStreamUtil(issue#1228@Github)
|
* 【core 】 新增CollStreamUtil(issue#1228@Github)
|
||||||
* 【extra 】 新增Rhino表达式执行引擎(pr#1229@Github)
|
* 【extra 】 新增Rhino表达式执行引擎(pr#1229@Github)
|
||||||
|
* 【crypto 】 增加判空(issue#1230@Github)
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【cron 】 修复CronTimer可能死循环的问题(issue#1224@Github)
|
* 【cron 】 修复CronTimer可能死循环的问题(issue#1224@Github)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package cn.hutool.core.codec;
|
package cn.hutool.core.codec;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BCD码(Binary-Coded Decimal)亦称二进码十进数或二-十进制代码<br>
|
* BCD码(Binary-Coded Decimal)亦称二进码十进数或二-十进制代码<br>
|
||||||
* BCD码这种编码形式利用了四个位元来储存一个十进制的数码,使二进制和十进制之间的转换得以快捷的进行<br>
|
* BCD码这种编码形式利用了四个位元来储存一个十进制的数码,使二进制和十进制之间的转换得以快捷的进行<br>
|
||||||
@ -58,6 +60,7 @@ public class BCD {
|
|||||||
* @return BCD
|
* @return BCD
|
||||||
*/
|
*/
|
||||||
public static byte[] ascToBcd(byte[] ascii) {
|
public static byte[] ascToBcd(byte[] ascii) {
|
||||||
|
Assert.notNull(ascii, "Ascii must be not null!");
|
||||||
return ascToBcd(ascii, ascii.length);
|
return ascToBcd(ascii, ascii.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +71,7 @@ public class BCD {
|
|||||||
* @return BCD
|
* @return BCD
|
||||||
*/
|
*/
|
||||||
public static byte[] ascToBcd(byte[] ascii, int ascLength) {
|
public static byte[] ascToBcd(byte[] ascii, int ascLength) {
|
||||||
|
Assert.notNull(ascii, "Ascii must be not null!");
|
||||||
byte[] bcd = new byte[ascLength / 2];
|
byte[] bcd = new byte[ascLength / 2];
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (int i = 0; i < (ascLength + 1) / 2; i++) {
|
for (int i = 0; i < (ascLength + 1) / 2; i++) {
|
||||||
@ -83,6 +87,7 @@ public class BCD {
|
|||||||
* @return ASCII字符串
|
* @return ASCII字符串
|
||||||
*/
|
*/
|
||||||
public static String bcdToStr(byte[] bytes) {
|
public static String bcdToStr(byte[] bytes) {
|
||||||
|
Assert.notNull(bytes, "Bcd bytes must be not null!");
|
||||||
char[] temp = new char[bytes.length * 2];
|
char[] temp = new char[bytes.length * 2];
|
||||||
char val;
|
char val;
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.codec.BCD;
|
|||||||
import cn.hutool.core.codec.Base64;
|
import cn.hutool.core.codec.Base64;
|
||||||
import cn.hutool.core.io.IORuntimeException;
|
import cn.hutool.core.io.IORuntimeException;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
import cn.hutool.core.util.HexUtil;
|
import cn.hutool.core.util.HexUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
@ -301,6 +302,7 @@ public abstract class AbstractAsymmetricCrypto<T extends AbstractAsymmetricCrypt
|
|||||||
* @since 4.1.0
|
* @since 4.1.0
|
||||||
*/
|
*/
|
||||||
public byte[] decryptFromBcd(String data, KeyType keyType, Charset charset) {
|
public byte[] decryptFromBcd(String data, KeyType keyType, Charset charset) {
|
||||||
|
Assert.notNull(data, "Bcd string must be not null!");
|
||||||
final byte[] dataBytes = BCD.ascToBcd(StrUtil.bytes(data, charset));
|
final byte[] dataBytes = BCD.ascToBcd(StrUtil.bytes(data, charset));
|
||||||
return decrypt(dataBytes, keyType);
|
return decrypt(dataBytes, keyType);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user