我试图从原始格式的CngKey以原始格式创建CngKey,但是即使所有格式正确,我仍然会遇到异常:
System.Security.Cryptography.CryptographicException:'参数不正确。'
具有以下调用堆栈:
System.Security.Cryptography.NCryptNative.ImportKey(Microsoft.Win32.SafeHandles.SafeNCryptProviderHandle, byte[], string)
System.Security.Cryptography.CngKey.Import(byte[], string, System.Security.Cryptography.CngKeyBlobFormat, System.Security.Cryptography.CngProvider)
System.Security.Cryptography.CngKey.Import(byte[], System.Security.Cryptography.CngKeyBlobFormat)
我正在Windows 10,.NET Framework 4.7.2上运行。 我正在运行的代码如下:
byte[] cngKeyRaw = new byte[] { 0x45, 0x43, 0x53, 0x31, 0x20, 0x00, 0x00, 0x00, 0x4B, 0xC9, 0x0A, 0x34, 0xF7, 0x92, 0xFF, 0x0D, 0x6A, 0x2A, 0x59, 0xB6, 0x73, 0x0A, 0x6C, 0x04, 0xFB, 0xEE, 0x99, 0xBF, 0x53, 0xDE, 0x00, 0x4B, 0x57, 0x9D, 0x01, 0xF5, 0x04, 0xDB, 0x1D, 0xD2, 0x21, 0xE6, 0x0C, 0xFF, 0xCC, 0xBA, 0x52, 0x58, 0x8C, 0xC0, 0xA3, 0x42, 0x57, 0xF6, 0x30, 0x8A, 0x44, 0xD9, 0x5A, 0x2E, 0x2A, 0x0A, 0xEC, 0x8D, 0x7F, 0x7D, 0xFD, 0x8E, 0x7B, 0x1A, 0xCB, 0xB3 };
var cngKey = CngKey.Import(cngKeyRaw, CngKeyBlobFormat.EccPublicBlob);
我一直在努力工作了好几个小时,没有任何在线资源对此有所帮助。 如果有人可以帮助我解决可能出现的问题,我将不胜感激!