Skip to content

Updating to openssl v3 replacing PEM_write_bio_RSAPublicKey #24331

Closed Answered by kulkarniamit
timlegge asked this question in Q&A
Discussion options

You must be logged in to vote

You can use encoders to define the output format.
Example:

   ...
   OSSL_ENCODER_CTX *ctx = NULL;
   const char *pubkey_out = "rsa.pub.pkcs1";
   ...
   fp_out = fopen(pubkey_out, "w");
   if (fp_out == NULL) {
       fprintf(stderr, "Failed to open public key to write\n");
       // handle errors and exit
   }

   ctx = OSSL_ENCODER_CTX_new_for_pkey(pkey, OSSL_KEYMGMT_SELECT_PUBLIC_KEY,
            "PEM", "PKCS1", NULL);
   if (ctx == NULL || !OSSL_ENCODER_CTX_get_num_encoders(ctx)) {
       fprintf(stderr, "Failed to get an encoder context\n");
       // handle errors and exit
   }

   fprintf(stdout, "Public key PKCS1 write to %s %s\n", pubkey_out,
       OSSL_ENCODER_to_fp(ctx, fp_out)…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@timlegge
Comment options

Answer selected by timlegge
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants