support x,y for sm2

This commit is contained in:
Looly
2020-03-05 00:49:07 +08:00
parent f37c1d529a
commit f6585adec4
11 changed files with 498 additions and 185 deletions

View File

@@ -1,6 +1,7 @@
package cn.hutool.core.util;
import java.awt.Color;
import java.math.BigInteger;
import java.nio.charset.Charset;
/**
@@ -198,6 +199,7 @@ public class HexUtil {
if (StrUtil.isEmpty(hexStr)) {
return null;
}
hexStr = StrUtil.removeAll(hexStr, ' ');
return decodeHex(hexStr.toCharArray());
}
@@ -338,6 +340,19 @@ public class HexUtil {
builder.append(toDigits[low]);
}
/**
* Hex16进制字符串转为BigInteger
* @param hexStr Hex(16进制字符串)
* @return {@link BigInteger}
* @since 5.2.0
*/
public static BigInteger toBigInteger(String hexStr){
if(null == hexStr){
return null;
}
return new BigInteger(hexStr, 16);
}
// ---------------------------------------------------------------------------------------- Private method start
/**

View File

@@ -38,4 +38,11 @@ public class HexUtilTest {
boolean isHex = HexUtil.isHexNumber(a);
Assert.assertTrue(isHex);
}
@Test
public void decodeTest(){
String str = "e8c670380cb220095268f40221fc748fa6ac39d6e930e63c30da68bad97f885d";
Assert.assertArrayEquals(HexUtil.decodeHex(str),
HexUtil.decodeHex(str.toUpperCase()));
}
}