int main() { BIO *bio_err; X509 *x509 = NULL; EVP_PKEY *pkey = NULL; CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); mkit(&x509, &pkey, 512, 0, 365); RSA_print_fp(stdout, pkey->pkey.rsa, 0); X509_print_fp(stdout, x509); PEM_write_PrivateKey(stdout, pkey, NULL, NULL, 0, NULL, NULL); PEM_write_X509(stdout, x509); X509_free(x509); EVP_PKEY_free(pkey); #ifdef CUSTOM_EXT /* Only needed if we add objects or custom extensions */ X509V3_EXT_cleanup(); OBJ_cleanup(); #endif CRYPTO_mem_leaks(bio_err); BIO_free(bio_err); return (0); }
int main(int argc, char *argv[]) { BIO *bio_err; X509 *x509=NULL; EVP_PKEY *pkey=NULL; FILE *f; #ifdef _WIN32 WSADATA data; #endif if(argc<2) { fprintf(stderr,"Usage: %s <filename>",argv[0]); return -1; } #ifdef _WIN32 if(WSAStartup (MAKEWORD (1, 1), &data)) { fprintf(stderr,"WSAStartup failed"); return -1; } #endif CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); bio_err=BIO_new_fp(stderr, BIO_NOCLOSE); mkit(&x509,&pkey,1024,0,3650); /* Passing 100 years here causes buffer overrun!! */ f = fopen(argv[1],"w"); if(!f) { perror("Couldn't create key file"); return -1; } PEM_write_PrivateKey(f,pkey,NULL,NULL,0,NULL, NULL); PEM_write_X509(f,x509); fclose(f); X509_free(x509); EVP_PKEY_free(pkey); CRYPTO_mem_leaks(bio_err); BIO_free(bio_err); return(0); }