This commit is contained in:
Looly 2021-12-09 01:26:33 +08:00
parent 95e8c812ef
commit 9468c132ff
4 changed files with 37 additions and 3 deletions

View File

@ -3,7 +3,7 @@
-------------------------------------------------------------------------------------------------------------
# 5.7.17 (2021-12-08)
# 5.7.17 (2021-12-09)
### 🐣新特性
* 【core 】 增加AsyncUtilpr#457@Gitee
@ -52,6 +52,7 @@
* 【core 】 修复QueryBuilder解析路径导致的错误issue#1989@Github
* 【core 】 修复DateTime.between中DateUnit无效问题
* 【poi 】 修复StyleUtil.getFormat非static问题issue#I4LGNP@Gitee
* 【crypto 】 修复SM2.getD返回bytes包含符号位的问题issue#2001@Github
-------------------------------------------------------------------------------------------------------------

View File

@ -1,6 +1,7 @@
package cn.hutool.core.math;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
public class CalculatorTest {
@ -30,7 +31,7 @@ public class CalculatorTest {
}
@Test
// @Ignore
@Ignore
public void conversationTest5(){
// https://github.com/dromara/hutool/issues/1984
final double conversion = Calculator.conversion("((1/1) / (1/1) -1) * 100");

View File

@ -19,7 +19,9 @@ import org.bouncycastle.crypto.signers.DSAEncoding;
import org.bouncycastle.crypto.signers.PlainDSAEncoding;
import org.bouncycastle.crypto.signers.SM2Signer;
import org.bouncycastle.crypto.signers.StandardDSAEncoding;
import org.bouncycastle.util.BigIntegers;
import java.math.BigInteger;
import java.security.PrivateKey;
import java.security.PublicKey;
@ -519,7 +521,27 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
* @since 5.5.9
*/
public byte[] getD() {
return this.privateKeyParams.getD().toByteArray();
return BigIntegers.asUnsignedByteArray(getDBigInteger());
}
/**
* 获得私钥D值编码后的私钥
*
* @return D值
* @since 5.7.17
*/
public String getDHex() {
return getDBigInteger().toString(16);
}
/**
* 获得私钥D值
*
* @return D值
* @since 5.7.17
*/
public BigInteger getDBigInteger() {
return this.privateKeyParams.getD();
}
/**

View File

@ -311,4 +311,14 @@ public class SM2Test {
byte[] dec = sm2.decrypt(data, KeyType.PrivateKey);
Assert.assertArrayEquals(dec, src.getBytes(StandardCharsets.UTF_8));
}
@Test
public void dLengthTest(){
final SM2 sm2 = SmUtil.sm2();
Assert.assertEquals(64, sm2.getDHex().length());
Assert.assertEquals(32, sm2.getD().length);
// 04占位一个字节
Assert.assertEquals(65, sm2.getQ(false).length);
}
}