mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix test and sm2 bug
This commit is contained in:
@@ -123,7 +123,7 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
if (KeyType.PublicKey != keyType) {
|
||||
throw new IllegalArgumentException("Encrypt is only support by public key");
|
||||
}
|
||||
ckeckKey(keyType);
|
||||
checkKey(keyType);
|
||||
|
||||
lock.lock();
|
||||
final SM2Engine engine = getEngine();
|
||||
@@ -149,7 +149,7 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
if (KeyType.PrivateKey != keyType) {
|
||||
throw new IllegalArgumentException("Decrypt is only support by private key");
|
||||
}
|
||||
ckeckKey(keyType);
|
||||
checkKey(keyType);
|
||||
|
||||
lock.lock();
|
||||
final SM2Engine engine = getEngine();
|
||||
@@ -234,6 +234,28 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SM2 setPrivateKey(PrivateKey privateKey) {
|
||||
super.setPrivateKey(privateKey);
|
||||
|
||||
// 重新初始化密钥参数,防止重新设置密钥时导致密钥无法更新
|
||||
this.privateKeyParams = null;
|
||||
initCipherParams();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SM2 setPublicKey(PublicKey publicKey) {
|
||||
super.setPublicKey(publicKey);
|
||||
|
||||
// 重新初始化密钥参数,防止重新设置密钥时导致密钥无法更新
|
||||
this.publicKeyParams = null;
|
||||
initCipherParams();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置加密类型
|
||||
*
|
||||
@@ -250,7 +272,7 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------------- Private method start
|
||||
/**
|
||||
* 初始化加密解密参数
|
||||
* 初始化加密解密参数(包括私钥和公钥参数)
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
@@ -291,7 +313,7 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
*
|
||||
* @param keyType key类型
|
||||
*/
|
||||
private void ckeckKey(KeyType keyType) {
|
||||
private void checkKey(KeyType keyType) {
|
||||
switch (keyType) {
|
||||
case PublicKey:
|
||||
if (null == this.publicKey) {
|
||||
|
@@ -154,8 +154,8 @@ public class SM2Engine {
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public static enum SM2Mode {
|
||||
C1C2C3, C1C3C2;
|
||||
public enum SM2Mode {
|
||||
C1C2C3, C1C3C2
|
||||
}
|
||||
|
||||
protected ECMultiplier createBasePointMultiplier() {
|
||||
@@ -348,8 +348,7 @@ public class SM2Engine {
|
||||
/**
|
||||
* 增加字段节点
|
||||
*
|
||||
* @param digest
|
||||
* @param v
|
||||
* @param v 节点
|
||||
*/
|
||||
private void addFieldElement(ECFieldElement v) {
|
||||
final byte[] p = BigIntegers.asUnsignedByteArray(this.curveLength, v.toBigInteger());
|
||||
|
Reference in New Issue
Block a user