Reputation: 61
I am implementing ECDSA keys and certificates in .NET, and I need to store the keys so that I can reuse them with a new signing. With RSA I was using the class RSACryptoServiceProvider, but I don't see anything similar with ECDsa neither ECDsaCng classes.
I only have seen DSACryptoServiceProvider and one old ECDsaCryptoServiceProvider to Framework 4.3 (a bit old).
Does anyone know a way to store ECDSA keys as in RSA, please?
Upvotes: 1
Views: 1261
Reputation: 33286
Assuming that you mean you would like to persist a key into the OS key store (RSACryptoServiceProvider using a named key), with CNG the interface is a little different:
private static ECDsa CreateOrOpenECDsaKey(string keyName)
{
CngKey key;
if (CngKey.Exists(keyName))
{
key = CngKey.Open(keyName);
}
else
{
// You can also specify options here, like if it should be exportable, in a
// different overload.
key = CngKey.Create(CngAlgorithm.ECDsaP521, keyName);
}
// The ECDsaCng constructor will duplicate the key reference, so we can close this one.
using (key)
{
return new ECDsaCng(key);
}
}
If you meant you want to do export/import like RSAParameters, that feature is present in .NET Core, but isn't yet present in .NET Framework.
Upvotes: 3