I've been working on signing and verifying files with ECDSA, and have got all my in-house tests working fine. However, I can't complete testing with my client, because they cannot import my public key.
I'm using CngKey.Export(CngKeyBlobFormat.EccPublicBlob)
, but it appears the format of the resulting byte[]
is proprietary (and therefore useless).
How might I export this in a more-common format (such as PEM or DER), that is readable by non-.NET users, without over-reliance on third-partly libraries (e.g. I don't want to have to rewrite everything to use BouncyCastle)?
For example, how do I get from:
const string keyName = "My Key";
var provider = CngProvider.MicrosoftSoftwareKeyStorageProvider;
var cngOptions = CngKeyOpenOptions.UserKey;
if (CngKey.Exists(keyName, provider, cngOptions))
{
using (var key = CngKey.Open(keyName, provider, cngOptions))
{
byte[] keyData = key.Export(CngKeyBlobFormat.EccPublicBlob);
}
}
...to:
-----BEGIN PUBLIC KEY-----
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAElkRqN7wIGwvHP0HCMuBZPS/L5ZDp4mBG
A5qssu1FumNtCEHQbjbUa46AvpXRL290Mr2iabTv9Z/SwDciihKZI6BrzSb1x060
WDgXslbTnzzh+lxne2AZtPPPzorZOiI7
-----END PUBLIC KEY-----
...?