blob: d7d06d50bfd0a5a83b26fdc9b35efcda8153eaa6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#include "cmd_sha1.h"
void *cmd_sha1(void *data)
{
char *param = (char *)data;
char *ret = NULL;
int i;
char hash_result[21];
char hex_result[41];
const int buf_size = 128;
char buf[buf_size+1];
printf("SHA1\n");
if (param == NULL)
{
ret = alloc_new_str("No params mate\n");
return ret;
}
SHA1(hash_result, param, strlen(param));
//cool way how to convert array to string
for (i=0;i<20;i++)
{
sprintf(hex_result+(2*i), "%02x", hash_result[i]&0xff);
}
hex_result[40]=0x0;
snprintf(buf, buf_size, "sha1 %s\n",hex_result);
ret = alloc_new_str(buf);
return ret;
}
|