mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix sm2 bug
This commit is contained in:
@@ -182,7 +182,6 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
if (KeyType.PublicKey != keyType) {
|
||||
throw new IllegalArgumentException("Encrypt is only support by public key");
|
||||
}
|
||||
checkKey(keyType);
|
||||
return encrypt(data, new ParametersWithRandom(getCipherParameters(keyType)));
|
||||
}
|
||||
|
||||
@@ -229,7 +228,6 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
if (KeyType.PrivateKey != keyType) {
|
||||
throw new IllegalArgumentException("Decrypt is only support by private key");
|
||||
}
|
||||
checkKey(keyType);
|
||||
return decrypt(data, getCipherParameters(keyType));
|
||||
}
|
||||
|
||||
@@ -450,26 +448,6 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查对应类型的Key是否存在
|
||||
*
|
||||
* @param keyType key类型
|
||||
*/
|
||||
private void checkKey(KeyType keyType) {
|
||||
switch (keyType) {
|
||||
case PublicKey:
|
||||
if (null == this.publicKey) {
|
||||
throw new NullPointerException("No public key provided");
|
||||
}
|
||||
break;
|
||||
case PrivateKey:
|
||||
if (null == this.privateKey) {
|
||||
throw new NullPointerException("No private key provided");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取{@link SM2Engine},此对象为懒加载模式
|
||||
*
|
||||
|
@@ -171,9 +171,7 @@ public class SM2Test {
|
||||
String id = "31323334353637383132333435363738";
|
||||
|
||||
final SM2 sm2 = new SM2(d, x, y);
|
||||
|
||||
final String sign = sm2.signHex(data, id);
|
||||
|
||||
Assert.assertTrue(sm2.verifyHex(data, sign));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user