SHA1 HMAC 与 Arduino 的字节数组
如何在 Arduino 上 HMAC 字节数组?我找到了用于 SHA1 HMAC 的此库,但它似乎仅用于字符串。
我已经以空终止字节数组的形式向它传递了字节。这确实给了我正确的结果。但对于包含零的字节数组来说效果不太好!
uint8_t hmacKey1[]={ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x21, 0xde, 0xad, 0xbe, 0xef };
uint8_t time[]={ 0xb2, 0x00 };
Sha1.initHmac(hmacKey1, 10);
Sha1.print((char*)time);
我要么需要找到另一个库(crypto-arduino-library看起来很有希望,但不包含任何我正在做的事情的示例),或者破解 Cathedrow 库来做我想做的事情。
有谁知道另一种方法吗?
How can I HMAC a byte array on an Arduino? I've found this library for SHA1 HMACs, but it appears to be used only for strings.
I've passed it bytes in a null-terminated byte array. This does give me the correct result. But doesn't work so well for byte arrays that contain zeros!
uint8_t hmacKey1[]={ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x21, 0xde, 0xad, 0xbe, 0xef };
uint8_t time[]={ 0xb2, 0x00 };
Sha1.initHmac(hmacKey1, 10);
Sha1.print((char*)time);
Either I need to find another another library (crypto-arduino-library looks promising, but doesn't include any examples for what I'm doing), or hack up the Cathedrow library to do what I'm after.
Does anyone know of another way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加我自己的方法似乎已经成功了:
Adding my own method appears to have done the trick:
如果您不想更改 sha1.cpp,您可以循环并打印每个字节,技巧是使用
Sha1.print((char) basestring[i]);
,如下所示:输出
If you don't want to change sha1.cpp you can just loop and print each single byte, the trick is to use
Sha1.print((char) basestring[i]);
, like so:Output