.NET Compact Framework 中的 RSA RSACryptoServiceProvider 使用完整 .NET Framework 中的公钥
在我的工作中,我们通过加密来保护数据,并且该数据由 .NET Compact Framework 加密,并且必须由服务器上的常规 .NET 框架读取。我们遇到了一个问题,即紧凑框架无法使用已知公钥的 RSA 进行加密(引发异常)。服务器将公钥传递给紧凑框架设备。下面是为紧凑框架编写的测试应用程序以显示问题。
string mod =
"rgTcL0/ZK3j5Rt6CigEsfyLDiERh2PuVzmZVdHbb/2jQOG5JEcAqqBoscDZ4PwJR8aO19xNVTce7"
+ "vzbEued32z2PLAvCcHFKGtOgNEeZ+ZcD6uHobsKws76BdjBrI7Pigk2HSkak21n2WoVcBVHoRmcn"
+ "eX7DPaB4atamhkbLoRBF1VlautDfhX9lnOFA2zyZUCB5CproavKF6wl19pZne2Q4U1vMtBAA2Q9N"
+ "aZFsrj/KjE3UtYKvjd4Oy55Hmtpb5P3CZAVpiyCTKq3gTxDJn69giyctu428DgkKacmZ4yTvkLWB"
+ "Ym/zWtAf9o8pI+3MwgF7wzuK5ypGack3l4/Skw==";
string exp = "AQAB";
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048);
RSAParameters p = new RSAParameters();
p.Modulus = Convert.FromBase64String(mod);
p.Exponent = Convert.FromBase64String(exp);
rsa.ImportParameters(p);
var bytes = rsa.Encrypt(System.Text.Encoding.ASCII.GetBytes("MIKE"), true);
当调用“Encrypt”方法时,此代码会产生以下异常:
Framework: 3.5.7283.0
Exception: fOAEP
InnerException: Could not evaluate expression
Stack Trace:
at System.Security.Cryptography.RSACryptoServiceProvider.Encrypt
(Byte[] rgb, Boolean fOAEP)
有人知道我还应该尝试/做什么吗?我已经用常规 .NET 编写了这段代码,并且运行得很好。我可以使用不同的实例进行加密和解密。任何帮助将不胜感激。
谢谢!
In my work we are doing encryption to protect data and that data is encrypted by the .NET Compact Framework and must be read by the regular .NET framework on a server. We are running into an issue where the compact framework is unable to encrypt (throwing exception) using RSA with a known public key. The server passes the public key to the compact framework device. Below is a test app written for the compact framework to show the problem.
string mod =
"rgTcL0/ZK3j5Rt6CigEsfyLDiERh2PuVzmZVdHbb/2jQOG5JEcAqqBoscDZ4PwJR8aO19xNVTce7"
+ "vzbEued32z2PLAvCcHFKGtOgNEeZ+ZcD6uHobsKws76BdjBrI7Pigk2HSkak21n2WoVcBVHoRmcn"
+ "eX7DPaB4atamhkbLoRBF1VlautDfhX9lnOFA2zyZUCB5CproavKF6wl19pZne2Q4U1vMtBAA2Q9N"
+ "aZFsrj/KjE3UtYKvjd4Oy55Hmtpb5P3CZAVpiyCTKq3gTxDJn69giyctu428DgkKacmZ4yTvkLWB"
+ "Ym/zWtAf9o8pI+3MwgF7wzuK5ypGack3l4/Skw==";
string exp = "AQAB";
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048);
RSAParameters p = new RSAParameters();
p.Modulus = Convert.FromBase64String(mod);
p.Exponent = Convert.FromBase64String(exp);
rsa.ImportParameters(p);
var bytes = rsa.Encrypt(System.Text.Encoding.ASCII.GetBytes("MIKE"), true);
This code produces the following exception when the "Encrypt" method is called:
Framework: 3.5.7283.0
Exception: fOAEP
InnerException: Could not evaluate expression
Stack Trace:
at System.Security.Cryptography.RSACryptoServiceProvider.Encrypt
(Byte[] rgb, Boolean fOAEP)
Does anyone know anything else I should try/do? I have written this code in regular .NET and it works just fine. I can encrypt and decrypt using different instances. Any help would be appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Compact Framework(至少在版本 3.5 中)不支持使用 fOAEP 参数的真值。有关该参数的详细信息,请参阅 http:// msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.encrypt.aspx。
在 CF 3.5 中,对
fOAEP = true
的支持似乎与设备无关。相反,拒绝true
值被硬编码为 Encrypt 方法中的参数验证。Use of a true value for the fOAEP parameter is not supported in the Compact Framework (at least in version 3.5). For details of the parameter, see http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.encrypt.aspx.
In CF 3.5, support for
fOAEP = true
does not appear to be device-dependent. Instead, rejection of atrue
value is hard-coded as a parameter validation in the Encrypt method.