diff --git a/dump.rdb b/dump.rdb index 074c2d9..54b7200 100644 Binary files a/dump.rdb and b/dump.rdb differ diff --git a/index.js b/index.js index 9a48c4f..c065226 100644 --- a/index.js +++ b/index.js @@ -142,11 +142,10 @@ module.exports = { if (this.isHashable(data) && this.isSeckey(seckey) && seckey.length===64) { // 纯 crypto let seckeyPEM = await new keyman.Key('oct', this.hex2buf(seckey), {namedCurve:'P-256K'}).export('pem') let hasher=my.HASHER_LIST.indexOf(option.hasher)>=0?option.hasher:my.HASHER - let inputEncoding=my.INPUT_LIST.indexOf(option.input)>=0?option.input:my.INPUT // 'utf8', 'ascii' or 'latin1' for string data, default to utf8 if not specified; ignored for Buffer, TypedArray, or DataView. let outputEncoding=(option.output==='buf')?undefined:(my.OUTPUT_LIST.indexOf(option.output)>=0?option.output:my.OUTPUT) let signer=crypto.createSign(hasher) - signer.update(data, inputEncoding).end() - let signature = signer.sign(seckeyPEM, outputEncoding) + signer.update(this.hash(data, option)).end() + let signature = signer.sign(seckeyPEM, 'hex') return signature // 发现同样的输入,每次调用会生成不同的 signature, 且长度不定(140~144 hex) 但都可以通过 verify。有一次我竟然徒手修改出一个新签名也通过验证。 } if (this.isHashable(data) && this.isSeckey(seckey) && seckey.length===128) { // 使用nacl的签名算法。注意,nacl.sign需要的seckey是64字节=128字符。 @@ -162,10 +161,8 @@ module.exports = { if (this.isHashable(data) && this.isSignature(signature) && this.isPubkey(pubkey) && signature.length>=140){ // 纯 crypto let pubkeyPEM = await new keyman.Key('oct', this.hex2buf(pubkey), {namedCurve:'P-256K'}).export('pem') let hasher=my.HASHER_LIST.indexOf(option.hasher)>=0?option.hasher:my.HASHER - let inputEncoding=my.INPUT_LIST.indexOf(option.input)>=0?option.input:my.INPUT // 'utf8', 'ascii' or 'latin1' for string data, default to utf8 if not specified; ignored for Buffer, TypedArray, or DataView. - let outputEncoding=(option.output==='buf')?undefined:(my.OUTPUT_LIST.indexOf(option.output)>=0?option.output:my.OUTPUT) let verifier = crypto.createVerify(hasher) - verifier.update(data, inputEncoding).end() // end() 在 nodejs 12 里返回verifier自身,但在浏览器里返回 undefined,因此不能串联运行。 + verifier.update(this.hash(data, option)).end() // end() 在 nodejs 12 里返回verifier自身,但在浏览器里返回 undefined,因此不能串联运行。 let verified = verifier.verify(pubkeyPEM, signature, 'hex') return verified }