我已经从http://gnuwin32.sourceforge.net/packages/openssl.htm为开发人员安装了 openssl 。然后,我将包含文件夹中的文件复制到 C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include 文件夹中。我将 lib 文件夹中的文件复制到 C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib 文件夹中。然后,我将库名称放入项目属性->链接器->输入->附加依赖项。当我运行程序时,它崩溃了。我该如何解决这个问题?
#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;
}