我安裝了此SHA庫:https://github.com/Cathedrow/Cryptosuite。我想使用安裝在Win上的Arduino IDE 1.6.7來實現HMAC256。 10和控制器是ATMEGA328。如何解決此問題:從'const char *'無效轉換爲'const uint8_t *
我複製了他們的網頁中給出的例子。我還是新手,想要測試和嘗試。我在Arduino IDE中編寫了這個代碼。
#include "sha256.h"
void setup() {
// put your setup code here, to run once:
uint8_t *hash;
//static const char hash[450]={};
//const char *hash; hash={};
Sha256.initHmac("hash key",8); // key, and length of key in bytes
Sha256.print("This is a message to hash");
hash = Sha256.resultHmac();
//Serial.print(hash,HEX);
}
void loop() {
// put your main code here, to run repeatedly:
}
我得到這個錯誤:
invalid conversion from 'const char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]
我不知道爲什麼會這樣。這個例子是從圖書館網站獲取的原始圖片。你能幫我嗎?
編輯: 我試圖更改從行:
Sha256.initHmac((const uint8_t*)"hash key",8);
到:
Sha256.initHmac((const uint8_t*)"hash key",8);
但同樣,編譯失敗。它說:
Arduino: 1.6.7 (Windows 10), Board: "Arduino/Genuino Uno"
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/arduino.h:28:0,
from C:\Users\e\Documents\Arduino\libraries\Sha\sha1_config.h:13, from C:\Users\e\Documents\Arduino\libraries\Sha\sha1.h:4, from C:\Users\e\Documents\Arduino\libraries\Sha\sha1.cpp:1:
C:\Users\e\Documents\Arduino\libraries\Sha\sha1.cpp:8:25: error: variable 'sha1InitState' must be const in order to be put into read-only section by means of 'attribute((progmem))'
uint8_t sha1InitState[] PROGMEM = {
^
exit status 1 Error compiling.
This report would have more information with "Show verbose output during compilation" enabled in File > Preferences.
謝謝。但沒有解決問題。查看已編輯的帖子。 – user2192774
查看更新(這是另一個與您的初始錯誤無關的問題) – jyvet
解決了問題:) –