Windows Phone API:使用RSACryptoServiceProvider对数据签名

本文关键字:数据 RSACryptoServiceProvider 使用 Phone API Windows | 更新日期: 2023-09-27 18:19:17

我的问题是:如何使用。net为Windows Phone签名数据,托管语言是c#

我使用RSACryptoServiceProvider生成一个私有/公共对,然后我想使用"SHA256Managed"哈希算法用私钥签名数据,我所做的是:

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());

execute and I got exception:类型为"System.Security.Cryptography"的异常。在mscorlib.ni.dll中发生CryptographicException',并且在托管/本机边界之前未处理指定的算法无效。

然后我将算法切换到SHA1或MD5,仍然得到相同的错误,然后我尝试:

SHA256Managed hashAlgorithm = new SHA256Managed();
byte[] hashedBytes = hashAlgorithm.ComputeHash(plainBytes);
signedBytes = rsaProvider.SighHash(hashedBytes, "1.2.840.113548.1.1.11");

则得到异常:类型为"System"的第一次机会异常。在mscorlib.ni.dll中发生NullReferenceException'对象引用未设置为对象的实例。

然后我放弃使用rsaProvider,并转向AsymmetricSignatureFormatter,我所做的是:

AsymmetricSignatureFormatter formatter = new RSAPKCS1SignatureFormatter();
formatter.SetHashAlgorithm("SHA256");
formatter.SetKey(rsaProvider);
signedBytes = formatter(plainBytes);

但仍然失败,我得到的是:类型的第一次机会异常类型为"System.Security.Cryptography"的异常。在mscorlib.ni.dll中发生CryptographicException',并且在托管/本机边界之前未处理指定的算法无效。

我搜索了很多线程,没有找到任何具体的例子为windows phone平台,谁能帮助我吗?

Windows Phone API:使用RSACryptoServiceProvider对数据签名

他们的网页声称他们已经在Windows Phone 7上成功地使用了这个方法。它甚至与RSACryptoServiceProvider兼容。http://www.dustinhorne.com/post/Asymmetric-Encryption-and-Signing-with-RSA-in-Silverlight.aspx

问题似乎是,发现符号(.pdb),源文件和二进制文件。我希望这会有所帮助启用编译器设置http://msdn.microsoft.com/en-us/library/ms241613.aspx BKMK_Specifying_symbol_locations_and_loading_behavior