Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SM2加密速度慢 SecureUtil.generateKeyPair("SM2");加入这段代码后由1000ms变几十毫秒 #3646

Closed
shizhenglg opened this issue Jul 8, 2024 · 1 comment
Labels

Comments

@shizhenglg
Copy link

版本情况

JDK版本: openjdk_8_201
hutool版本: 5.8.9(请确保最新尝试是否还有问题)

问题描述(包括截图)

  1. 复现代码
final SM2 sm2 = SmUtil.sm2("xxxxxx", "xxxxx");

// 加入这段代码之后 加密时间由1000ms变为几十ms
		SecureUtil.generateKeyPair("SM2");
		// 公钥加密,私钥解密
		long t1 = System.currentTimeMillis();
		byte[] encrypt = sm2.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
		long t2 = System.currentTimeMillis();
		System.out.println(t2-t1);
		byte[] decrypt = sm2.decrypt(encrypt, KeyType.PrivateKey);
		Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));

加入以下代码为什么会变快呢?
SecureUtil.generateKeyPair("SM2");

@looly
Copy link
Member

looly commented Jul 10, 2024

原因来自Linux下随机种子生成的问题。

可以搜下相关内容,修改为非阻塞方式。

@looly looly added the question label Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants