问题描述
我想接收带有椭圆曲线签名的签名消息 hello
并验证它。
此代码是服务器端,它从客户端接收消息及其签名。但是,它没有验证它,因为签名有问题。
代码:
var mqtt = require('mqtt')
const EC = require('elliptic').ec;
const ec = new EC('secp256k1');
var broker_URL = 'mqtt://localhost';
var client = mqtt.connect(broker_URL);
client.on('connect',function () {
console.log("MQTT connected "+ client.connected);
client.subscribe('Bcmessage');
client.subscribe('BCsignature');
})
client.on('message',function (topic,message) {
if (topic === 'Bcmessage'){
var msg = message.toString();
} else if (topic === 'BCsignature'){
var sig = message.toString();
}
var key = ec.keyFrompublic('0473891deb0cb162c568592d806ef91eb3eab0ae0eb76b72c92d88b6c47789d1dd64b6c9aeb8c564267ed69dba205df45d6586c7907cbd5f0f5ba61291500809e0','hex');
console.log(key.verify(msg,sig));
});
客户端:
let myKey = ec.keyFromPrivate('29f3c33a550d3810e6b82b7b510672118aeabcf8b19e00172e4623cbf480d2b8');
const sig = myKey.sign("hello",'base64');
var sighex = sig.toDER('hex');
client.publish("Bcmessage","hello");
client.publish("BCsignature",sighex);
错误:
assert(options.r && options.s,'Signature without r or s');
^
TypeError: Cannot read property 'r' of undefined
我不明白错误以及如何修复它!签名中的字符串/十六进制有问题吗? 提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)