c# - 如何使用提供的 RSA 公钥加密 App.config 文件的一部分
问题描述
我有某人的公钥作为字符串:
<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;
}
}
我怎么能告诉它要进行加密,它应该使用公钥而不是它正在运行的当前机器上的公钥?
解决方案
推荐阅读
- javascript - html图像的奇怪压缩
- reactjs - Redux 模拟商店仅在分派多个操作时返回一个操作
- c++ - 将整数行直接读入向量
- c++ - std::function 如何接受具有相同函数调用运算符签名的所有函数对象?
- python - pandas.DataFrame 和 pandas.Series 对象对 pandas.get_dummies() 的作用不同
- sharepoint - 对象引用未设置为对象的实例 - Sharepoint 上的 SSRS
- javascript - 在函数中使用 if 语句的问题
- aws-sdk - 如何通过密钥而不是 id AWS APIGateway 获取 api 密钥
- php - 如何在 CodeIgniter 中使用带有 jquery 验证的 ajax 上传图像?
- typescript - 我可以使用固定键创建地图吗?