gpt4 book ai didi

c - 使用 libgcrypt 签名,崩溃

转载 作者:行者123 更新时间:2023-11-30 19:41:24 25 4
gpt4 key购买 nike

我正在尝试创建一个由具有主私钥的对等点控制的对等网络,其中一部分是批准对等点进行连接

以下代码假设采用公钥,对其进行签名并将其发送给对等方,以便它可以检查其是否有效以及是否在其批准的对等方列表中

gcry_sexp_t signature, keydata;
char *blob = malloc(size + 64);

sprintf(blob, "(data\n (flags pkcs1)\n (hash sha1 #%.*s#))\n", (int)size, buf);
printf("%s\n", blob);
free(buf);

gcry_sexp_sscan(&keydata, &size, blob, strlen(blob));
printf("offset %d\n", (int)size);

size = gcry_sexp_sprint(keydata, GCRYSEXP_FMT_ADVANCED, NULL, 0);
printf("size %d\n", (int)size);

buf = gcry_xmalloc(size);
gcry_sexp_sprint(keydata, GCRYSEXP_FMT_ADVANCED, buf, size);
printf("keydata: %.*s\n", size, buf);
free(buf);

gcry_pk_sign(&signature, keydata, skey);
size = gcry_sexp_sprint(signature, GCRYSEXP_FMT_ADVANCED, NULL, 0);
buf = gcry_xmalloc(size);
gcry_sexp_sprint(signature, GCRYSEXP_FMT_ADVANCED, buf, size);
//add signature buf to msg and send to peer

但是它崩溃了。有什么想法吗?

最佳答案

printf 参数的方式是错误的。应该是:

printf("keydata: %.*s\n", size, buf);

关于c - 使用 libgcrypt 签名,崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33599531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com