Thread: sha1?
View Single Post
Old 10-07-2003, 01:38 AM  
Join Date: Jan 2003
Posts: 91
Thumbs up

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;
dasOp is offline