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

循环加密解密好像会报错 #1

Closed
lucky2046 opened this issue Jul 1, 2018 · 3 comments
Closed

循环加密解密好像会报错 #1

lucky2046 opened this issue Jul 1, 2018 · 3 comments

Comments

@lucky2046
Copy link

var sm2 = require('sm-crypto').sm2;
var sm3 = require('sm-crypto').sm3;
var sm4 = require('sm-crypto').sm4;
var assert = require('assert');

var plainMsg = 'hello world!';
var keypair = sm2.generateKeyPairHex();
console.log('keypair:' + keypair);

var i = 0
for (;;) {
i++;
if (i == 1000) {
i = 0;
}
var encryptData = sm2.doEncrypt(plainMsg, keypair.publicKey);
console.log('encrypt result:' + encryptData);
var decryptData = sm2.doDecrypt(encryptData, keypair.privateKey);
console.log('decrypt result:' + decryptData);
assert.equal(plainMsg == decryptData, true, 'error');

// var hashResult = sm3(plainMsg);
// console.log('sm3 hash:' + hashResult);

}

@JuneAndGreen
Copy link
Owner

这里确实是存在着问题,我抽时间修复一下。

painterQ added a commit to painterQ/sm-crypto that referenced this issue Dec 26, 2018
JuneAndGreen added a commit that referenced this issue Dec 26, 2018
@JuneAndGreen
Copy link
Owner

感谢 @painterQ 帮忙修复此问题,测试用例已补充。

@wangjun796
Copy link

dist 中SM2随机出错,加密的数据 别的加密机或解密卡不能解密(自己加自己解没有问题,自己加的数据送到加密机不能解密 出错率 10%左右)一下抓取了一条出错数据:
明文:"11111111"
密文:1db3c72f5f0d012e2e56c6b92ea7f4081b49e2fd93e4a89c59cbe2dd028d8c8328d357b8e5e4e43ed395aa439d7fe032f92858ea0d53a02526a36eadb34faaa92ea1646f642f53812a4fc38876dbf253d38ea2ba4096d876462840b7b51c33b5719c09b08a170655
私钥:46D77D6E14C1DDC632159FA6E2AC3E204F6961869342DC99BC2684EDD71C57AB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants