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!
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
}