title: openssl c++ need to display public key in hex format
body: <p>I could use some help, I need to display a public key the same way Windows does when double clicking on a certificate (see image).  Thanks.</p>
  
  <p>I can get the public key with either:</p>
  
  <p>RSA *pubKey = X509_get_pubkey( csc->current_cert )->pkey.rsa;</p>
  
  <p>or</p>
  
  <p>EVP_PKEY *pubKey = X509_get_pubkey(csc->current_cert);</p>
  
  <p>If found this snippet somewhere but the values I get are different from what Windows displays:</p>
  
  <pre><code>unsigned char enc_bin[1024] = {0};
  int enc_len = 0;
  unsigned char dec_bin[1024] = {0};
  int dec_len = 0;
  
  enc_len = RSA_size( pubKey );
  memset( enc_bin, 1, enc_len );
  
  if( 0 &lt; ( dec_len = RSA_public_decrypt( enc_len, enc_bin, dec_bin, pubKey, RSA_NO_PADDING) ) )
  {
      for (int i = 0; i &lt; dec_len; i++)
      {
          CString str;
          if( 0 == i )
              str.Format( L"%02X", dec_bin[i] );
          else
              str.Format( L" %02X", dec_bin[i] );
  
          PubKey += str;
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/qfehn.png" alt="enter image description here"></p>