I'm trying to read get the x, y and d parameter values from a pem file generated using https://mkjwk.org/ with P 256 curve, Encryption, ECDH-ES+A128KW with X509 set to true. The values for x, y , d are retrieved using below:
using (var reader = new StringReader(privateKeyString))
{
var param = (ECPrivateKeyParameters)new PemReader(reader).ReadObject();
x = param.Parameters.G.AffineXCoord.GetEncoded();
y = param.Parameters.G.AffineYCoord.GetEncoded();
d = param.D.ToByteArrayUnsigned();
}
But the statement below is throwing exception when executed in remote server with Windows Server 2012 but running fine in local system running on Windows 10:
var privateKey = EccKey.New(x, y, d, CngKeyUsages.KeyAgreement);
The exception found in remote is given below:
The requested operation is not supported at System.Security.Cryptography.NCryptNative.ImportKey(SafeNCryptProviderHandle provider, Byte[] keyBlob, String format) at System.Security.Cryptography.CngKey.Import(Byte[] keyBlob, String curveName, CngKeyBlobFormat format, CngProvider provider) at Jose.keys.EccKey.New(Byte[] x, Byte[] y, Byte[] d, CngKeyUsages usage)...
I am using the below library for my purpose: https://github.com/dvsekhvalnov/jose-jwt