如何以及在哪里存储用于加载 p12 证书文件的密码

How and where to store password for loading p12 certificate file

我正在尝试加载带有密码的 p12 证书文件,我想知道在生产环境中存储和使用密码的最佳做法是什么。

正在使用的代码是:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

var handler = new WebRequestHandler();
var certificate = new X509Certificate2Collection();
certificate.Import(@"D:\certificate.p12", "password", X509KeyStorageFlags.DefaultKeySet);
handler.ClientCertificates.AddRange(certificate);
handler.ServerCertificateValidationCallback = ValidateServerCertificate;

var client = new HttpClient(handler)
{
    BaseAddress = new Uri(chargeCodeServer)
};

正在使用的密码在以下行中:

certificate.Import(@"D:\certificate.p12", "password", X509KeyStorageFlags.DefaultKeySet);

我们使用 TeamCity、Octopus 和 Powershell 脚本进行部署。如果还有其他需要,请告诉我。

Octopus Deploy 允许您存储 "sensitive" 变量。当您使用敏感标志时,它不会在 Octopus UI 或 Octopus 日志文件中显示值。

您的所有 Octopus 变量都可以在任何 Powershell 部署任务中使用。

变量由您的 Octopus 主密钥保护,所以我认为这是保存此类信息的合理位置 - 特别是因为 Octopus 非常擅长允许您使用(例如)不同的证书在每个环境中,具有不同的凭据。