[英]Cannot read X509 object into a temporary file using openssl for windows C programming
int _tmain(int argc, _TCHAR* argv[])
{
X509 *x;
EVP_PKEY *pkey;
PKCS12 *p12;
STACK_OF(X509) *ca=NULL;
FILE *fp;
int code;
CRYPTO_malloc_init();
SSL_library_init();
SSL_load_error_strings();
ERR_load_BIO_strings();
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
x = X509_new();
code = fopen_s(&fp,PRIVATE_CERTIFICATE, "rb");
//fp = fopen(PRIVATE_CERTIFICATE, "rb");
p12 = d2i_PKCS12_fp(fp, NULL);
fclose(fp);
if (!PKCS12_parse(p12, KEYPASS, &pkey, &x, &ca)) {
printf(" Error while parsing\n");
}
PKCS12_free(p12);
code = fopen_s(&fp,TEMP_STORE_CERTIFICATE, "w");
PEM_write_X509(fp, x);
fclose(fp);
//RSA Private Certificate
fp = fopen(TEMP_STORE_KEY_CERTIFICATE,"w");
PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL);
fclose(fp);
return 0;
}
When the execution gets up to PEM_write_X509, it gets stuck and does not proceed. 当执行执行到PEM_write_X509时,它被卡住并且无法继续。 I guess, it enters into the infinite loop, and the execution doesnt goes beyond that. 我猜,它进入了无限循环,执行没有超出此范围。 A console simply opens up which doesnt goes away. 控制台只是打开而不会消失。 Someone please help 有人请帮忙
File pointed by fp is opened into "rb" mode where PEM_write_fp will try to write on a file which is already opened into read mode. 将由fp指向的文件打开为“ rb”模式,其中PEM_write_fp将尝试在已打开为读取模式的文件上进行写操作。 Close the file and open it into write mode before writing. 在写入之前,请关闭文件并使其进入写入模式。
Moreover, it does not seems good to overwrite the content of the file. 而且,覆盖文件的内容似乎不太好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.