我正在开发一个为 ASP.Net Web 服务器加密配置文件设置的应用程序。我正在实施的加密方法是使用 AES 和 RSA 封装数据。我正在生成一个 AES 密钥,使用该 AES 密钥加密我的数据,然后使用我的 Windows 证书存储中的证书中的公钥加密 AES 密钥。然后,我将数据连同加密的 AES 密钥以及用于加密它的证书序列号一起保存回配置文件。
当我想访问这些数据时,我读取了用于加密 AES 密钥的证书序列号,从该证书中提取私钥,解密 AES 密钥,然后使用该密钥解密数据。这是我不确定我的安全级别的地方。
为了访问与证书关联的私钥,我必须将私钥标记为可导出,并为我的应用程序运行的用户提供对私钥的访问权限。由于这是一个 ASP.Net 服务器,因此该用户是“网络服务”。我相信您会明白为什么这会是一个安全问题。基本上,如果有人通过网络闯入我的 ASP.Net 服务器,也许通过某种注入,他们将有权访问该私钥,不是吗?
有人对如何使我的模型更安全有任何建议吗?
解密功能:
//need an rsa crytpo provider to decrypt the aes key with the private key associated with the certificate
using (RSACryptoServiceProvider rsaCSP = (RSACryptoServiceProvider) decryptionCertificate.PrivateKey)
{
//decrypt the aes key with the cert's private key
byte[] aesKey = rsaCSP.Decrypt(encryptedAESKey, false);
//decrypt data using the decrypted aes key and the IV passed in
decryptedData = decryptWithAes(encryptedData, aesKey, aesIV);
}
谢谢。