mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
13afb47a42
commit
f806e3b855
@ -41,6 +41,7 @@ import org.dromara.hutool.crypto.bc.SmUtil;
|
||||
import java.math.BigInteger;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
/**
|
||||
* 国密SM2非对称算法实现,基于BC库<br>
|
||||
@ -71,6 +72,10 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
|
||||
private ECPrivateKeyParameters privateKeyParams;
|
||||
private ECPublicKeyParameters publicKeyParams;
|
||||
/**
|
||||
* 自定义随机数
|
||||
*/
|
||||
private SecureRandom random;
|
||||
|
||||
private DSAEncoding encoding = StandardDSAEncoding.INSTANCE;
|
||||
private Digest digest = new SM3Digest();
|
||||
@ -238,7 +243,7 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
if (KeyType.PublicKey != keyType) {
|
||||
throw new IllegalArgumentException("Encrypt is only support by public key");
|
||||
}
|
||||
return encrypt(data, new ParametersWithRandom(getCipherParameters(keyType)));
|
||||
return encrypt(data, new ParametersWithRandom(getCipherParameters(keyType), this.random));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -366,7 +371,7 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
lock.lock();
|
||||
final SM2Signer signer = getSigner();
|
||||
try {
|
||||
CipherParameters param = new ParametersWithRandom(getCipherParameters(KeyType.PrivateKey));
|
||||
CipherParameters param = new ParametersWithRandom(getCipherParameters(KeyType.PrivateKey), this.random);
|
||||
if (id != null) {
|
||||
param = new ParametersWithID(param, id);
|
||||
}
|
||||
@ -483,6 +488,17 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置随机数生成器,可自定义随机数种子
|
||||
*
|
||||
* @param random 随机数生成器,可自定义随机数种子
|
||||
* @return this
|
||||
*/
|
||||
public SM2 setRandom(final SecureRandom random) {
|
||||
this.random = random;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置DSA signatures的编码为PlainDSAEncoding
|
||||
*
|
||||
|
@ -224,7 +224,7 @@ public class BCCipher implements Cipher, Wrapper<Object> {
|
||||
/**
|
||||
* 算法的参数
|
||||
*/
|
||||
private final CipherParameters parameters;
|
||||
protected final CipherParameters parameters;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
Loading…
x
Reference in New Issue
Block a user