【发布时间】:2020-12-05 09:21:36
【问题描述】:
我正在使用 GetSecretAsync() 方法从 Azure Key Vault 获取我的证书,然后我希望最终获得私钥和证书的字节[]。
我在 .netcore3.1 中有我的应用程序 这就是我的代码的样子:
var certWithPrivateKey = Client.GetSecretAsync(ConfigurationSettings.AppSettings["AKVEndpoint"], ConfigurationSettings.AppSettings["CertName"]).GetAwaiter().GetResult();
var privateKeyBytes = Convert.FromBase64String(certWithPrivateKey.Value);
X509Certificate2 x509Certificate = new X509Certificate2(privateKeyBytes);
var privateKey = x509Certificate.GetRSAPrivateKey() as RSA;
我获得了 RSACng 类型的有效 privateKey,但任何操作(尝试 ExportRSAPrivateKey())都会引发错误“'privateKey.ExportRSAPrivateKey()' 引发了类型为 'Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException'”的异常和“不支持请求的操作。”
我不知道接下来如何继续获取私钥和证书的字节[]。
【问题讨论】:
-
为什么不用密钥而不是秘密?
-
为什么需要导出私钥?最终目标是什么?
-
我想最终将该证书安装在我的 kubernetes 集群中作为 tls 机密,所以我希望获得私钥和证书的字节 [] 最终制作一个 .cer 和 .key 文件和使用它们来创建秘密。
标签: c# .net-core cryptography private-key x509certificate2