I did catch the idea. And it is quite simple. It did take me an hour to figure your code out though. Here below is a simple example for the benefit of others:
#include "sha1.h"
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
unsigned char hash[20]; //20 bytes is whats specd
char outbuf[40 + 1]; //result hash is 40 bytes plus NUL
char* pass = "ioFTPD";
sha1(hash, (unsigned char*)pass, strlen(pass));
for (int i = 0; i < 20; ++i)
{
int s = (int)((unsigned char*)hash)[i]; //using int just to avoid loss
sprintf(outbuf + i * 2, "%02x", s); //what we're outputting here is a byte, nothing else
}
outbuf[40] = '\0';
printf("Password hash for user %s is %s\r\n", pass, outbuf);
return 0;
}
|