我已经为http://gnuwin32.sourceforge.net/packages/openssl.htm的开发人员安装了openssl。然后,我将include文件夹中的文件复制到C:\ Program Files(x86)\ Microsoft Visual Studio 11.0 \ VC \ include文件夹中。我将lib文件夹中的文件复制到C:\ Program Files(x86)\ Microsoft Visual Studio 11.0 \ VC \ lib文件夹中。然后,我将库名称放入项目属性 - > linker-> input->其他依赖项。当我运行程序时,它崩溃了。我该如何解决这个问题?
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/pkcs12.h>
/* Simple PKCS#12 file reader */
unsigned char *getValue( X509 *cert,int index);
unsigned char *getTckn( X509 *cert);
unsigned char *getRelease( X509 *cert);
unsigned char *getNameSurname( X509 *cert);
unsigned char *getCity( X509 *cert);
unsigned char *getUserType( X509 *cert);
int main(int argc, char **argv) {
FILE *fp;
EVP_PKEY *pkey;
X509 *cert;
STACK_OF(X509) *ca = NULL;
PKCS12 *p12;
const char* fileName = "C:/Users/sercan/Desktop/EBA/eba.p12";
fprintf(stderr, "Error", fileName);
OpenSSL_add_all_algorithms();
fprintf(stderr, "Error", fileName);
ERR_load_crypto_strings();
if (!(fp = fopen(fileName, "rb "))) {
fprintf(stderr, "Error opening file %s\n", argv[1]);
exit(1);
}
fprintf(stderr, "Error", fileName);
p12 = d2i_PKCS12_fp(fp, NULL);
fclose(fp);
if (!p12) {
fprintf(stderr, "Error reading PKCS#12 file\n");
ERR_print_errors_fp(stderr);
exit(1);
}
if (!PKCS12_parse(p12, argv[2], &pkey, &cert, &ca)) {
fprintf(stderr, "Error parsing PKCS#12 file\n");
ERR_print_errors_fp(stderr);
exit(1);
}
PKCS12_free(p12);
return 0;
}
答案 0 :(得分:1)
尝试从此处下载OpenSSL:http://slproweb.com/products/Win32OpenSSL.html 它对我来说很好。 另请阅读README文件,该文件说明了如何相应地设置项目。