【问题标题】:How to store Public Certiticate (.cer file) in Azure Key Vault如何在 Azure Key Vault 中存储公共证书(.cer 文件)
【发布时间】:2018-01-06 00:32:16
【问题描述】:

如何在 azure keyvault 中上传或存储公钥 (.cer) 文件。当我尝试上传适用于 .pfx 文件的任何 .cer 文件时,从 keyvault 面板中出现错误。

【问题讨论】:

    标签: azure-keyvault


    【解决方案1】:

    加载公钥证书

    Azure Key Vault Explorer 允许您加载公钥证书(.cer 文件)。

    证书使用该应用程序使用的“标准”格式作为密钥存储在 Key Vault 中(因为 Azure Key Vault 本身不支持 .cer 文件)。

    访问公钥证书

    将公钥加载到 Azure Key Vault 后,就可以按如下方式以编程方式访问它们:

    // load certificate based on format used by `Azure Key Vault Explorer`
    var azureServiceTokenProvider = new AzureServiceTokenProvider();
    var kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
    var certBundle = await kv.GetSecretAsync(secretIdentifier).ConfigureAwait(false);
    
    byte[] certBytes = null;
    if (certBundle.ContentType == "application/x-pkcs12")
    {
        certBytes = Convert.FromBase64String(certBundle.Value);
    }
    else if (certBundle.ContentType == "application/pkix-cert")
    {
        certBytes = certBundle?.Value.FromJson<PublicKeyCertificate>()?.Data;
    }
    if (certBytes != null && certBytes.Length > 0)
    {
        return new X509Certificate2(certBytes,
            "",
            X509KeyStorageFlags.Exportable |
            X509KeyStorageFlags.MachineKeySet |
            X509KeyStorageFlags.PersistKeySet);
    }
    return null;
    
    ...
    
    // class used to access public key certificate stored in Key Vault
    public class PublicKeyCertificate
    {
        public byte[] Data;
    }
    

    【讨论】:

    • 对于那些遵循这些说明的人。使用 https://aka.ms/ve?vault://[ENTER HERE YOUR VAULT NAME] 安装 Azure Vault。然后,在 Vault 应用程序中,按 Add > Key Vault Certificate > From File。选择您的 .cer 文件并按 OK。
    【解决方案2】:

    您应该考虑 Key Vault 是否适合您的方案。公钥(本质上)不是机密数据,您不需要安全的地方来存储它。您可以为其使用通用存储服务。

    如果您仍需要使用 Key Vault,可以将其存储为机密。 Key Vault 机密是八位字节序列,每个最大大小为 25k 字节。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-11
      • 2020-01-27
      • 1970-01-01
      • 2021-01-18
      • 1970-01-01
      • 2020-01-24
      • 2020-08-11
      • 1970-01-01
      相关资源
      最近更新 更多