Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X.509 Certificate Public Key in Base64

I am trying to find the base64 public key for a certificate I am working with. The public key I find in the detail tab of the certificate is not base64 and I am requested to provide the base64 public key.

Is there a way I can get a base64 version of public key? Can it be done by taking the public key from the certificate and encrypting it to base64? For example, below is the public key I find for a certificate:

" 30 82 01 0a 02 82 01 01 00 bc 39 25 06 5d 99 a4 05 5f e7 fc 59 1f 28 b5 48 d2 0d 2e ea aa eb ed 74 ef c9 2f 90 f8 ad 96 80 24 0f c2 dc 71 58 ea 3e fa 5c c9 29 87 51 7c cb 54 28 7c f9 10 15 b0 ac 8f eb 9e d3 d7 70 35 93 8a c7 1f 45 97 e3 c8 0b 72 a1 65 79 cf 74 6c 87 d9 eb 7d a0 b9 0e 4b 45 3d 81 f0 18 6e 9f 97 11 54 cb d8 e2 35 1a 4b e7 4d bf 68 1d ad 4e ca 57 25 9e 2f f7 f8 44 6f c2 0c 78 d8 19 ef 22 5a 9f 78 9f 17 1a b8 c0 72 0f 51 5c 21 6f c9 1e 80 de 7c 25 47 d0 28 01 2a 94 6e 34 39 1f 42 39 be 5f 0e c2 7c b4 fa a5 b9 05 4e 9c 45 75 63 a3 87 c3 e5 dd 54 35 85 d4 8d c2 5f da 6f 86 12 cf b3 8b 65 23 1d 34 43 c5 2e b1 49 56 56 25 93 f7 09 bf 9e 48 21 91 6a de 27 9e 6d 38 2f f5 f4 93 23 46 e8 41 b4 21 b4 02 50 79 71 48 72 0f 57 46 a0 20 c0 19 02 f9 d4 76 02 2d 85 fd 79 cd 70 fc 41 8b 02 03 01 00 01 "

How can I convert this to base64? Thank you for all the help!

like image 687
user2220871 Avatar asked Jun 30 '14 14:06

user2220871


People also ask

Does x509 certificate contain public key?

An X. 509 certificate consists of two keys, namely a public key and a private key. This key pair, depending upon the application, allows you to sign documents using the private key so that the intended person can verify the signature using the public key related to it.

What is Base64 encoded X 509 certificate?

A DER file is an X. 509 digital certificate encoded in binary – 1's and 0's. Base64 is a binary-to-text encoding scheme, so a PEM file, which is a Base64 encoded DER file, is that same X. 509 certificate, but encoded in text, which (remember!) is represented as ASCII.

Are certificates in Base64?

Base64 is the industry standard format for SSL certificate content. The most common web servers will generate a certificate signing requests as well as accept SSL certificates in base-64 format. The size of the certificate content will depend on the encryption strength of the certificate.

How do I know if my certificate is Base64 or der?

To determine if a certificate file is base64 or DER binary, open the file in Notepad. If the text "Begin Certificate" appears at the beginning of the file, it is in base64 format. If "Begin Certificate" does not appear at the beginning of the file, it is in DER binary format.


2 Answers

I'll assume you're on windows.

The way I did it was to install the certificate. Open certificates (from mmc or directly) Open the certificate in question.

In the details tab, there is the option to 'Copy To File'. Press next until it gives you the export file format.

Select Base-64 encoded X.509 (.cer). Save to Desktop.

If you open this file with notepad, it will display the base64 encoded public key in between the ----BEGIN CERTIFICATE---- and -----END CERTIFICATE------

Edit:

I save this base64 string and then convert back in code to get the actual certificate. It's pretty easy.

var base64Cert = // read from Db or somewhere
var base64EncodedStr = Encoding.Unicode.GetString(base64Cert);
var cert = new X509Certificate2(Convert.FromBase64String(base64EncodedStr), "password", X509KeyStorageFlags.PersistKeySet);
if(cert != null)
{
    // use certificate
}
like image 64
Peter Lea Avatar answered Oct 17 '22 02:10

Peter Lea


You could use ASN.1 Editor. It has a nice Data Converter which allows you to convert from HEX, BASE64, PEM to any of the before mentioned.

enter image description here

like image 22
pepo Avatar answered Oct 17 '22 03:10

pepo