Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 267495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:33:37+00:00 2026-05-11T23:33:37+00:00

I have a certificate in der format, from it with this command I generate

  • 0

I have a certificate in der format, from it with this command I generate a public key:

openssl x509 -inform der -in ejbcacert.cer -noout -pubkey > pub1key.pub

Which results in this:

-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7vbqajDw4o6gJy8UtmIbkcpnk
O3Kwc4qsEnSZp/TR+fQi62F79RHWmwKOtFmwteURgLbj7D/WGuNLGOfa/2vse3G2
eHnHl5CB8ruRX9fBl/KgwCVr2JaEuUm66bBQeP5XeBotdR4cvX38uPYivCDdPjJ1
QWPdspTBKcxeFbccDwIDAQAB
-----END PUBLIC KEY-----

How can I obtain a public key like this? Either from certificate or
from this public key?

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC7vbqajDw4o6gJy8UtmIbkcpnkO3Kwc4qsEnSZp/TR+fQi62F79RHWmwKOtFmwteURgLbj7D/WGuNLGOfa/2vse3G2eHnHl5CB8ruRX9fBl/KgwCVr2JaEuUm66bBQeP5XeBotdR4cvX38uPYivCDdPjJ1QWPdspTBKcxeFbccDw==

This was obtained with this command:

ssh-keygen -y -f private_key1.pem > public_key1.pub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:33:38+00:00Added an answer on May 11, 2026 at 11:33 pm

    To answer my own question, after posting on openssl mailing list got this:

    Here is C code to convert from an OpenSSL public key to an OpenSSH public key.
    You can grab the code from this link and compile it yourself:

    static unsigned char pSshHeader[11] = { 0x00, 0x00, 0x00, 0x07, 0x73, 0x73, 0x68, 0x2D, 0x72, 0x73, 0x61};
    
    static int SshEncodeBuffer(unsigned char *pEncoding, int bufferLen, unsigned char* pBuffer)
    {
       int adjustedLen = bufferLen, index;
       if (*pBuffer & 0x80)
       {
          adjustedLen++;
          pEncoding[4] = 0;
          index = 5;
       }
       else
       {
          index = 4;
       }
       pEncoding[0] = (unsigned char) (adjustedLen >> 24);
       pEncoding[1] = (unsigned char) (adjustedLen >> 16);
       pEncoding[2] = (unsigned char) (adjustedLen >>  8);
       pEncoding[3] = (unsigned char) (adjustedLen      );
       memcpy(&pEncoding[index], pBuffer, bufferLen);
       return index + bufferLen;
    }
    
    int main(int argc, char**  argv)
    {
       int iRet = 0;
       int nLen = 0, eLen = 0;
       int encodingLength = 0;
       int index = 0;
       unsigned char *nBytes = NULL, *eBytes = NULL;
       unsigned char* pEncoding = NULL;
       FILE* pFile = NULL;
       EVP_PKEY *pPubKey = NULL;
       RSA* pRsa = NULL;
       BIO *bio, *b64;
    
       ERR_load_crypto_strings(); 
       OpenSSL_add_all_algorithms();
    
       if (argc != 3)
       {
          printf("usage: %s public_key_file_name ssh_key_description\n", argv[0]);
          iRet = 1;
          goto error;
       }
    
       pFile = fopen(argv[1], "rt");
       if (!pFile)
       {
          printf("Failed to open the given file\n");
          iRet = 2;
          goto error;
       }
    
       pPubKey = PEM_read_PUBKEY(pFile, NULL, NULL, NULL);
       if (!pPubKey)
       {
          printf("Unable to decode public key from the given file: %s\n", ERR_error_string(ERR_get_error(), NULL));
          iRet = 3;
          goto error;
       }
    
       if (EVP_PKEY_type(pPubKey->type) != EVP_PKEY_RSA)
       {
          printf("Only RSA public keys are currently supported\n");
          iRet = 4;
          goto error;
       }
    
       pRsa = EVP_PKEY_get1_RSA(pPubKey);
       if (!pRsa)
       {
          printf("Failed to get RSA public key : %s\n", ERR_error_string(ERR_get_error(), NULL));
          iRet = 5;
          goto error;
       }
    
       // reading the modulus
       nLen = BN_num_bytes(pRsa->n);
       nBytes = (unsigned char*) malloc(nLen);
       BN_bn2bin(pRsa->n, nBytes);
    
       // reading the public exponent
       eLen = BN_num_bytes(pRsa->e);
       eBytes = (unsigned char*) malloc(eLen);
       BN_bn2bin(pRsa->e, eBytes);
    
       encodingLength = 11 + 4 + eLen + 4 + nLen;
       // correct depending on the MSB of e and N
       if (eBytes[0] & 0x80)
          encodingLength++;
       if (nBytes[0] & 0x80)
          encodingLength++;
    
       pEncoding = (unsigned char*) malloc(encodingLength);
       memcpy(pEncoding, pSshHeader, 11);
    
       index = SshEncodeBuffer(&pEncoding[11], eLen, eBytes);
       index = SshEncodeBuffer(&pEncoding[11 + index], nLen, nBytes);
    
       b64 = BIO_new(BIO_f_base64());
       BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
       bio = BIO_new_fp(stdout, BIO_NOCLOSE);
       BIO_printf(bio, "ssh-rsa ");
       bio = BIO_push(b64, bio);
       BIO_write(bio, pEncoding, encodingLength);
       BIO_flush(bio);
       bio = BIO_pop(b64);
       BIO_printf(bio, " %s\n", argv[2]);
       BIO_flush(bio);
       BIO_free_all(bio);
       BIO_free(b64);
    
    error:
       if (pFile)
          fclose(pFile);
       if (pRsa)
          RSA_free(pRsa);
       if (pPubKey)
          EVP_PKEY_free(pPubKey);
       if (nBytes)
          free(nBytes);
       if (eBytes)
          free(eBytes);
       if (pEncoding)
          free(pEncoding);
    
       EVP_cleanup();
       ERR_free_strings();
       return iRet;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 171k
  • Answers 171k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer While not a "blit" at all, given the requirements of… May 12, 2026 at 2:13 pm
  • Editorial Team
    Editorial Team added an answer If it needs to be unique, then I would forget… May 12, 2026 at 2:13 pm
  • Editorial Team
    Editorial Team added an answer The JMS FAQ says JMS API messaging provides guaranteed delivery… May 12, 2026 at 2:13 pm

Related Questions

Backstory: I have a PKCS#12 (p12) certificate with a symmetric cipher (password) that I
Motorola phones do not have Verisign/Thawte root certificates for code signing. They only embed
I have two certificates that I saved to disk. One is a certificate with
I have a pkcs12 file. I need to use this to connect to a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.