我正在使用这个sh1功能。我想将它存储在char数组或字符串中以进行进一步处理,而不是打印哈希值。
#include "sha1.h"
#include <stdlib.h>
void setup(){
Serial.begin(9600);
}
void loop() {
uint8_t *hash;
Sha1.init();
Sha1.print("This is a message to hash");
hash = Sha1.result();
for (int j=0;j<20;j++)
Serial.print("0123456789abcdef"[hash>>4]);
Serial.print("0123456789abcdef"[hash&0xf]);
}
Serial.println();
delay(1000);
}
答案 0 :(得分:0)
char digitArray[]= {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
char buffer[40];
for (int i = 0; i<40; i+=2){
buffer[i] = digitArray[(hash[i/2] & 0xF0) >> 4];
buffer[i+1] = digitArray[(hash[i/2] & 0x0F)];
}