I'm trying to get the SHA256 sum of a UTF-16le string. Pythonically what I'm trying to do would look like this:
import hashlib
username = "Administrator"
username = username.decode('utf-8').encode('utf-16le')
hash = hashlib.sha256(username).digest()
print(hash)
The C code below gives me the SHA256 hash as though I had NOT called the decode('utf-8').encode('utf-16le') in the Python section above.
The output of the below is e7d3e769f3f593dadcb8634cc5b09fc90dd3a61c4a06a79cb0923662fe6fae6b. The output that I want would be 5264c63204c56c0df9f8f4a030ea19d93a0fa402be6b00b4d7464e61641021f7
This is my first time coding in C, so if I'm missing something blatantly obvious or doing something wrong, that's why.
#include <openssl/sha.h>
#include <stdio.h>
#include <string.h>
int main()
{
unsigned const char ibuf[] = "Administrator";
unsigned char obuf[32];
SHA256(ibuf, strlen((const char * )ibuf), obuf);
unsigned char hash[32];
int i;
for(i = 0; i < 32; i++)
{
printf("%02x",obuf[i]);
}
printf("\n");
return 0;
}