SHA256

i am trying to copy the output of hash output to another array and here is my code

 #include "sha256.h"
#include <Arduino.h>
#include "./printf.h"


     char arr[33] ;
 uint8_t* hash;
void printHash(uint8_t* hash) {
  
 
  for (int i=0; i<32; i++) {
     
    Serial.print("0123456789abcdef"[hash[i]>>4]);
    Serial.print("0123456789abcdef"[hash[i]&0xf]);
 
  }
  Serial.println();
}


void setup() {
 
  
  Serial.begin(9600);


  
}


void loop() {
      
char xx[21];
String str ="12345678901234567890";
str.toCharArray(xx, 21);
 

Sha256.initHmac((uint8_t*)xx,21);


  Sha256.print("node 1");

 hash=Sha256.resultHmac();
  
 


for( int j=0;j<32;j++)
{arr[j]=hash[j];
arr[32]='\0';
  Serial.print(arr[j],HEX);
  
}

Serial.print('\n');


  
}

when i print hash i get the expected digest
A22E26CD62834B901E43F4D871D063B51CDE769D3396D1774EEDDBD892B73F91
but when i print arr[j] i a strange digest
FFFFFFA22E26FFFFFFCD62FFFFFF834BFFFFFF901E43FFFFFFF4FFFFFFD871FFFFFFD063FFFFFFB51CFFFFFFDE76FFFFFF9D33FFFFFF96FFFFFFD1774EFFFFFFEDFFFFFFDBFFFFFFD8FFFFFF92FFFFFFB73FFFFFFF91
how can i fix that ?
thx in advance for ur help

how can i fix that ?

The Print() class does not have overloads to print every type, so, some types get promoted to other types. In particular, there are differences between how signed and unsigned types are handled. You almost certainly want arr to be an unsigned type, like hash is, not a signed type. char is a signed type.

You can add an overload to the Print class, to print a signed type in HEX properly.

Or, you can use a type that the Print class already handles correctly.

thanks PaulS

i just declared arr as a byte instead of char

use this code
it doesn't need any external header files etc