【发布时间】:2011-08-17 14:21:37
【问题描述】:
我正在尝试使用来自 OpenSSL 的 DSA 进行签名。我有包含公钥和私钥的文件。
首先,我建立了单播连接,一切都很好。之后,我需要一个多播 UDP 连接,并且我想对数据包进行签名。我正在尝试使用函数PEM_read_DSA_PUBKEY() 来从我的证书加载我的公钥,但它不起作用。它总是返回 NULL 而不是 DSA 结构。
这里有一个简化版本的代码。我是这样编译的:
gcc -Wall -g -lm prueba.c -o prueba -lcrypto
有什么想法吗?谢谢!
#include <stdio.h>
#include <openssl/dsa.h>
#include <openssl/pem.h>
int main()
{
FILE *DSA_cert_file = fopen("./certs/cert.pem", "r");
if (DSA_cert_file == NULL)
return 1;
printf("Certificate read\n");
DSA *dsa = DSA_new();
if((dsa = PEM_read_DSA_PUBKEY(DSA_cert_file, 0, 0, 0)) == NULL)
return 1;
printf("DSA public key read\n");
return 0;
}
【问题讨论】: