[英]Can RSACryptoServiceProvider.Decrypt() return incorrect data?
Can System.Security.Cryptography.RSACryptoServiceProvider.Decrypt()
output incorrect data? System.Security.Cryptography.RSACryptoServiceProvider.Decrypt()
output 数据是否不正确? Or will it always throw Exception with message "The parameter is incorrect" or any other Exception, whether it's unable to decrypt in a proper way?或者它是否总是会抛出带有消息“参数不正确”或任何其他异常的异常,无论它是否无法以正确的方式解密?
Situation is:情况是:
RSACryptoServiceProvider.ExportParameters(true)
我使用RSACryptoServiceProvider.ExportParameters(true)
生成 RSA 对Is this even possible?这甚至可能吗? What am I missing here?我在这里想念什么?
using System.Security.Cryptography;
var provider = new RSACryptoServiceProvider(2048);
var rsaParams = provider.ExportParameters(true);
rsaParams.Exponent = new byte[] { 0x65 };
byte[] publicKey = rsaParams.Modulus;
// Send public key to the other side with exponent 0x65,
// Decrypt received data
byte[] decryptedData = provider.Decrypt(encryptedData, false);
You cannot just replace the public exponent like you do after key generation (which happens in the constructor).您不能像在密钥生成之后那样替换公共指数(这发生在构造函数中)。 By default a public exponent is likely set to 65537 (fifth prime of Fermat, F4) and you just set it to 0x65
.默认情况下,公共指数可能设置为 65537(费马的第五个素数,F4),您只需将其设置为0x65
。 If the public and private key do not match then the calculations will fail.如果公钥和私钥不匹配,则计算将失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.