0
votes

I have installed openssl for developers from http://gnuwin32.sourceforge.net/packages/openssl.htm. Then, I copy the files in include folder into C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include folder. I copy the files in lib folder into C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib folder. Then, I put library names into project properties->linker->input->additional dependies. When I run the program, it crashes. How can I fix the problem?

#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;

}
1
Did you get any error message or exceptions?Ami
What are the Linker Errors you are getting?Abhineet
I didn't get any exception, it craches when executing OpenSSL_add_all_algorithms();dijkstra

1 Answers

1
votes

Try to download OpenSSL from here: http://slproweb.com/products/Win32OpenSSL.html It worked fine for me. Also read the README file, which explains how to setup your project accordingly.