I have the following problem, and cant find solution:
While consuming APN (Apple push notifications) API, i implemented tokenized authorization. It's apple's new way of authorization on their push notifications api.
Apple provides me private key, which i use to create c# CngKey object, which then i use to sign data.
CngKey key = CngKey.Import(
Convert.FromBase64String(privateKey),
CngKeyBlobFormat.Pkcs8PrivateBlob);
using (ECDsaCng dsa = new ECDsaCng(key))
{
dsa.HashAlgorithm = CngAlgorithm.Sha256;
var unsignedJwtData =
Url.Base64urlEncode(Encoding.UTF8.GetBytes(header)) + "." + Url.Base64urlEncode(Encoding.UTF8.GetBytes(payload));
var signature =
dsa.SignData(Encoding.UTF8.GetBytes(unsignedJwtData));
return unsignedJwtData + "." + Url.Base64urlEncode(signature);
}
The result is signed token, which i then use as authorization header while consuming API and sending push notifications.
It works well on my dev machine, but when i deploy it to Windows Server, when this code runs i get next:
System.ArgumentException: Keys used with the ECDsaCng algorithm must have an algorithm group of ECDsa.
Parameter name: key
at System.Security.Cryptography.ECDsaCng..ctor(CngKey key)
at OTTCommon.Encryption.ECDSA.SignES256(String privateKey, String header, String payload, ILog log)
I cant find solution, it is something with windows key storage or something like that....
What should i do?