带有智能卡的ECDsaCng-> CryptographicException [英] ECDsaCng with smart card -> CryptographicException
问题描述
当我运行以下代码时,我得到CryptographicException.
When I run following code, I get CryptographicException.
using (c1 = CngKey.Open("ecc_test_card21_384", CngProvider.MicrosoftSmartCardKeyStorageProvider, CngKeyOpenOptions.UserKey))
{
using (ECDsaCng ecsdKey = new ECDsaCng(c1))
{
ecsdKey.SignData(dataX);
}
}
System.Security.Cryptography.CryptographicException未处理
Message =参数不正确.
Source = System.Core
StackTrace:
v System.Security.Cryptography.NCryptNative.GetProperty(SafeNCryptHandle ncryptObject,String propertyName,CngPropertyOptions propertyOptions,Boolean&foundProperty)
v System.Security.Cryptography.CngKey.get_IsEphemeral()
v System.Security.Cryptography.ECDsaCng..ctor(CngKey键)
InnerException:
Source=System.Core
StackTrace:
v System.Security.Cryptography.NCryptNative.GetProperty(SafeNCryptHandle ncryptObject, String propertyName, CngPropertyOptions propertyOptions, Boolean& foundProperty)
v System.Security.Cryptography.CngKey.get_IsEphemeral()
v System.Security.Cryptography.ECDsaCng..ctor(CngKey key)
InnerException:
按以下顺序使用C而非C#可以正常工作
Using C not C# with following sequence works fine
NCryptOpenStorageProvider
NCryptOpenKey
NCryptSignHash
是否有解决方案,如何将 ECDsaCng与智能卡一起使用?
Is there a solution how to use ECDsaCng with smart card?
Lukas
推荐答案
我假设open语句正在工作,并且您在SignData()方法上遇到错误.
I assume the open statement is working and you are getting the error on the SignData() method.
您可能是由于 dataX而出现错误.我需要更多地了解在C#和C代码中获取此变量的方式.您可能正在从文件中以7位模式而不是8位模式读取密钥.查看 您流式编码方法.
You are probably getting the error because of dataX. I would need to know more about the way this variable is obtained in the C# and C code. You may be reading the key in 7 bit mode rather than 8 bith mode from a file. Check you stream encoding method.
这篇关于带有智能卡的ECDsaCng-> CryptographicException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!