Hello all...
I try to get private key and certificates from p12
file that generate from NS certificate server but I
have a problem. I can't get priKey and certs from
function PKCS12_parse(). When I call this function,
It will return '0'. Is that mean there're something
wrong? Please see my code and screen output.My output
file (test.p12) has zero length.
################# C O D E ###################
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/err.h>
#include <openssl/pkcs12.h>
int main() {
BIO *in=NULL,*out=NULL;
PKCS12 *p12_r = NULL,*p12_w=NULL;
EVP_PKEY *pkey=NULL;
X509 *cert=NULL;
//STACK *chain=NULL;
char *infile = "tk_um_ns.p12";
char *outfile = "test.p12";
int ret=1;
/*READ P12 FILE*/
printf("hi 1\n");
in = BIO_new_file(infile, "rb");
if (!in) {
printf("Error opening input file %s\n",infile);
perror (infile);
return(-1);
}
printf("hi 2\n");
if (!(p12_r = d2i_PKCS12_bio (in, NULL))) {
printf("Error read p12_bio");
return(-1);
}
printf("hi 3\n");
ret = PKCS12_parse(p12_r,"cse51naht", &pkey, &cert,
NULL);
printf("ret=%d\n",ret);
/*WRITE P12 FILE*/
printf("hi 4\n");
p12_w = PKCS12_create("test", "TEST Certificate",
pkey, cert, NULL,0,0,0,0,0);
printf("hi 5\n");
out = BIO_new_file(outfile, "wb");
if (!out) {
printf("Error opening output file
%s\n",outfile);
perror (outfile);
return(-1);
}
printf("hi 6\n");
i2d_PKCS12_bio (out, p12_w);
PKCS12_free(p12_w);
BIO_free(out);
printf("hi 7\n");
return(0);
}
############ S C R E E N O U T P U T #############
hi 1
hi 2
hi 3
ret=0
hi 4
hi 5
hi 6
hi 7
Press any key to continue
=====
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]