我将某人的公钥作为字符串:
<RSAKeyValue>
<Modulus>publickeyhere</Modulus>
<Exponent>AAAA</Exponent>
</RSAKeyValue>
我也有一个app.config文件,我正在尝试使用公共密钥加密它的appSettings部分。我就是这样
var publicKeyXml = @"<RSAKeyValue><Modulus>publickeyhere</Modulus><Exponent>AAAA</Exponent></RSAKeyValue>";
var map = new ExeConfigurationFileMap
{
ExeConfigFilename = "app.config"
};
var config = ConfigurationManager
.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
using (var rsa = new RSACryptoServiceProvider())
{
try
{
rsa.FromXmlString(publicKeyXml);
// Now use the public key to encrypt how?
config.AppSettings.SectionInformation
.ProtectSection("RSAProtectedConfigurationProvider");
config.SaveAs($"app.encrypted.config");
}
finally
{
rsa.PersistKeyInCsp = false;
}
}
我如何告诉它进行加密,它应该使用公钥而不是运行它的当前计算机上的一个?