通过添加系统属性hutool.crypto.decodeHex强制关闭hex识别以解决hex和Base64歧义问题

This commit is contained in:
Looly
2024-02-10 08:37:15 +08:00
parent 6accf8fca0
commit e948273f2d
26 changed files with 169 additions and 158 deletions

View File

@@ -12,7 +12,7 @@
package org.dromara.hutool.core.codec.hash.metro;
import org.dromara.hutool.core.codec.HexUtil;
import org.dromara.hutool.core.codec.binary.HexUtil;
import org.dromara.hutool.core.codec.Number128;
import org.dromara.hutool.core.util.ByteUtil;
import org.junit.jupiter.api.Assertions;
@@ -128,6 +128,6 @@ public class MetroHash128Test {
}
private static String hex(final byte[] bytes){
return HexUtil.encodeHexStr(bytes).toUpperCase();
return HexUtil.encodeStr(bytes).toUpperCase();
}
}

View File

@@ -12,7 +12,7 @@
package org.dromara.hutool.core.codec.hash.metro;
import org.dromara.hutool.core.codec.HexUtil;
import org.dromara.hutool.core.codec.binary.HexUtil;
import org.dromara.hutool.core.util.ByteUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -125,6 +125,6 @@ public class MetroHash64Test {
}
private static String hex(final byte[] bytes){
return HexUtil.encodeHexStr(bytes).toUpperCase();
return HexUtil.encodeStr(bytes).toUpperCase();
}
}

View File

@@ -13,7 +13,7 @@
package org.dromara.hutool.core.codec.hash.metro;
import org.dromara.hutool.core.codec.HexUtil;
import org.dromara.hutool.core.codec.binary.HexUtil;
import org.dromara.hutool.core.codec.hash.CityHash;
import org.dromara.hutool.core.util.ByteUtil;
import org.dromara.hutool.core.util.CharsetUtil;

View File

@@ -12,7 +12,7 @@
package org.dromara.hutool.core.convert;
import org.dromara.hutool.core.codec.HexUtil;
import org.dromara.hutool.core.codec.binary.HexUtil;
import org.dromara.hutool.core.collection.set.SetUtil;
import org.dromara.hutool.core.date.DateException;
import org.dromara.hutool.core.date.DateUtil;
@@ -416,7 +416,7 @@ public class ConvertTest {
public void toFloatTest(){
// https://gitee.com/dromara/hutool/issues/I4M0E4
final String hex2 = "CD0CCB43";
final byte[] value = HexUtil.decodeHex(hex2);
final byte[] value = HexUtil.decode(hex2);
final float f = Convert.toFloat(value);
Assertions.assertEquals(406.1F, f, 0);
}

View File

@@ -12,7 +12,7 @@
package org.dromara.hutool.core.io.checksum;
import org.dromara.hutool.core.codec.HexUtil;
import org.dromara.hutool.core.codec.binary.HexUtil;
import org.dromara.hutool.core.io.checksum.crc16.CRC16XModem;
import org.dromara.hutool.core.util.ByteUtil;
import org.junit.jupiter.api.Assertions;

View File

@@ -12,8 +12,7 @@
package org.dromara.hutool.core.util;
import org.dromara.hutool.core.codec.HexUtil;
import org.dromara.hutool.core.util.CharsetUtil;
import org.dromara.hutool.core.codec.binary.HexUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -30,15 +29,15 @@ public class HexUtilTest {
public void hexStrTest(){
final String str = "我是一个字符串";
final String hex = HexUtil.encodeHexStr(str, CharsetUtil.UTF_8);
final String decodedStr = HexUtil.decodeHexStr(hex);
final String hex = HexUtil.encodeStr(str, CharsetUtil.UTF_8);
final String decodedStr = HexUtil.decodeStr(hex);
Assertions.assertEquals(str, decodedStr);
}
@Test
public void issueI50MI6Test(){
final String s = HexUtil.encodeHexStr("".getBytes(StandardCharsets.UTF_16BE));
final String s = HexUtil.encodeStr("".getBytes(StandardCharsets.UTF_16BE));
Assertions.assertEquals("70df", s);
}
@@ -75,8 +74,8 @@ public class HexUtilTest {
@Test
public void decodeTest(){
final String str = "e8c670380cb220095268f40221fc748fa6ac39d6e930e63c30da68bad97f885d";
Assertions.assertArrayEquals(HexUtil.decodeHex(str),
HexUtil.decodeHex(str.toUpperCase()));
Assertions.assertArrayEquals(HexUtil.decode(str),
HexUtil.decode(str.toUpperCase()));
}
@Test
@@ -88,8 +87,8 @@ public class HexUtilTest {
@Test
public void decodeHexTest(){
final String s = HexUtil.encodeHexStr("6");
final String s1 = HexUtil.decodeHexStr(s);
final String s = HexUtil.encodeStr("6");
final String s1 = HexUtil.decodeStr(s);
Assertions.assertEquals("6", s1);
}
}