C# Windows Phone API:使用RSACryptoServiceProvider对数据进行签名
我的问题是:如何使用.Net for Windows Phone对数据进行签名,托管语言是C 我使用RSACryptServiceProvider生成私钥/公钥对,然后我想使用SHA256Managed Hash算法用私钥对数据签名,我所做的是:C# Windows Phone API:使用RSACryptoServiceProvider对数据进行签名,c#,.net,windows-phone-8,cryptography,digital-signature,C#,.net,Windows Phone 8,Cryptography,Digital Signature,我的问题是:如何使用.Net for Windows Phone对数据进行签名,托管语言是C 我使用RSACryptServiceProvider生成私钥/公钥对,然后我想使用SHA256Managed Hash算法用私钥对数据签名,我所做的是: string DataTobeEncrypt = "upupdowndownleftleftrightrightABstart"; CspParameter cspParams = new CspParameters(); cspParams = ne
string DataTobeEncrypt = "upupdowndownleftleftrightrightABstart";
CspParameter cspParams = new CspParameters();
cspParams = new CspParameters();
cspParams.ProviderType = 1; // PROV_RSA_FULL
cspParams.Flags = CspProviderFlags.UseArchivableKey;
cspParams.KeyNumber = (int)KeyNumber.Exchange;
RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(2048,cspParams);
byte[] plainBytes = Encoding.Unicode.GetBytes(DataTobeEncrypt);
byte[] signedBytes = rsaProvider.SignHash(plainBytes, new SHA256Managed());
执行时,我遇到异常:
mscorlib.ni.dll中发生“System.Security.Cryptography.CryptographyException”类型的异常,在托管/本机边界之前未处理该异常
指定的算法无效
然后我将算法切换到SHA1或MD5,仍然得到相同的错误,然后我尝试:
SHA256Managed hashAlgorithm = new SHA256Managed();
byte[] hashedBytes = hashAlgorithm.ComputeHash(plainBytes);
signedBytes = rsaProvider.SighHash(hashedBytes, "1.2.840.113548.1.1.11");
然后我得到一个例外:
mscorlib.ni.dll中发生类型为“System.NullReferenceException”的第一次意外异常
对象引用未设置为对象的实例
然后我放弃使用rsaProvider,转而使用AsymmetricSignatureFormatter,我所做的是:
AsymmetricSignatureFormatter formatter = new RSAPKCS1SignatureFormatter();
formatter.SetHashAlgorithm("SHA256");
formatter.SetKey(rsaProvider);
signedBytes = formatter(plainBytes);
但它仍然失败了,我得到的是:第一次机会的类型异常
mscorlib.ni.dll中发生“System.Security.Cryptography.CryptographyException”类型的异常,在托管/本机边界之前未处理该异常
指定的算法无效
我搜索了很多线程,没有找到任何关于windows phone平台的具体示例,有人能帮我吗?他们的网页声称他们已经在windows phone 7中成功使用了它。它甚至与RSACryptServiceProvider兼容。 问题似乎是,Symbol.pdb、源代码和二进制文件。我希望这会有所帮助 启用编译器设置