fix sm2 bug

This commit is contained in:
Looly
2020-04-14 16:26:32 +08:00
parent b4568dd2e3
commit 8102b31373
4 changed files with 8 additions and 32 deletions

View File

@@ -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},此对象为懒加载模式
*

View File

@@ -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));
}
}