G-wan C Sha1哈希

时间:2012-11-06 15:17:35

标签: c sha g-wan

我遇到一个小问题,让sha1功能在G-WAN中运行。

基本上我有我想要哈希的字符串,我是C的新手,所以任何指针都是 大。

这是我试图sha1哈希的字符串,我尝试了几种方法,但我不确定我做错了什么。

u8 *input = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";

我几乎有使用G-wan的websockets,最后一件事就是让这个sha1函数与我合作。

关于G-wans sha1功能的文档在

之下
// u8 dst[20]; // the resulting 160-bit hash
// sha1_t ctx;
// sha1_init(&ctx);
// int i = 10;
// while(i--)
//    sha1_add(&ctx, data[i].ptr, data[i].len);
// sha1_end(&ctx, dst);

typedef struct { u8 x[220]; } sha1_t;
void sha1_init(sha1_t *ctx);
void sha1_add (sha1_t *ctx, u8 *src, int srclen);
void sha1_end (sha1_t *ctx, u8 *dst);
// a wrapper on all the above SHA-160 calls
void sha1(u8 *input, int ilen, u8 *dst);

链接到api http://gwan.com/api

如果有人可以在这里给我一块骨头这会让我在C的最后几个小时有点宽容。

1 个答案:

答案 0 :(得分:1)

以下是有关如何使用sha1函数的示例。

u8 input[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
u8 result[20];

sha1(input, sizeof(input) - 1, result);
xbuf_xcat(get_reply(argv), "SHA1 Result: %20B", result);

结果是二进制,因此您需要将其转换为B64或HEX以使其可读。 '%B'是G-WAN中的B64转换。 '%20B'告诉它转换前20个字节。

结果:

  

SHA1结果:Kfh9QIsMVZcl6xEPYxPHzW8SZ8w =

相关问题