如果你想用自己的私钥以及检索您的证书,那么你可以导出它通过您的磁盘上的一个PFX文件(密码为空):
$vaultName = "my-vault-name"
$certificateName = "my-cert-name"
$pfxPath = [Environment]::GetFolderPath("Desktop") + "\$certificateName.pfx"
$pfxSecret = Get-AzureKeyVaultSecret -VaultName $vaultName -Name $certificateName
$pfxUnprotectedBytes = [Convert]::FromBase64String($pfxSecret.SecretValueText)
[IO.File]::WriteAllBytes($pfxPath, $pfxUnprotectedBytes)
如果你想查看刚才在内存中的私有密钥本身没有写入磁盘,然后尝试:
$vaultName = "my-vault-name"
$certificateName = "my-cert-name"
$pfxPath = [Environment]::GetFolderPath("Desktop") + "\$certificateName.pfx"
$pfxSecret = Get-AzureKeyVaultSecret -VaultName $vaultName -Name $certificateName
$pfxUnprotectedBytes = [Convert]::FromBase64String($pfxSecret.SecretValueText)
$pfx = New-Object Security.Cryptography.X509Certificates.X509Certificate2
$pfx.Import($pfxUnprotectedBytes, $null, [Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$pfx.PrivateKey.ExportParameters($true)
除了指数和模数外,还将显示私有参数。
如果你想保护磁盘上的PFX文件用自己的密码(按“检索PFX文件&添加密码改回”在this blog post指令),然后尝试:
$vaultName = "my-vault-name"
$certificateName = "my-cert-name"
$pfxPath = [Environment]::GetFolderPath("Desktop") + "\$certificateName.pfx"
$password = "my-password"
$pfxSecret = Get-AzureKeyVaultSecret -VaultName $vaultName -Name $certificateName
$pfxUnprotectedBytes = [Convert]::FromBase64String($pfxSecret.SecretValueText)
$pfx = New-Object Security.Cryptography.X509Certificates.X509Certificate2
$pfx.Import($pfxUnprotectedBytes, $null, [Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$pfxProtectedBytes = $pfx.Export([Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12, $password)
[IO.File]::WriteAllBytes($pfxPath, $pfxProtectedBytes)
如REST API文档here和here中所述,Azure密钥保管库(AKV)通过三个相互关联的资源(AKV证书,AKV密钥和AKV密钥)表示给定的X.509证书。所有三者将共享相同的名称和相同的版本 - 要验证此情况,请检查Get-AzureKeyVaultCertificate
的响应中的Id
,KeyId
和SecretId
属性。
每个3个资源的用于观看给定的X.509证书提供不同的角度:
- 的AKV证书提供了X.509证书的公钥证书和元数据。它包含公钥的模数和指数(
n
和e
)以及其他证书元数据(指纹,失效日期,主题名称等)。在PowerShell中,您可以通过获得此:
(Get-AzureKeyVaultCertificate -VaultName $vaultName -Name $certificateName).Certificate
- 的AKV键提供了X.509证书的私钥。如果相应的证书被标记为不可导出,那么执行密码操作(如签名)可能会很有用。在PowerShell中,您只能获得通过这个私钥的公共部分:
(Get-AzureKeyVaultKey -VaultName $vaultName -Name $certificateName).Key
- 的AKV秘密提供了一种导出全X.509证书,包括其私人密钥(如果其策略允许私钥导出)。
(Get-AzureKeyVaultSecret -VaultName $vaultName -Name $certificateName).SecretValueText
非常彻底响应,由于阿德:如上所示,可以在PowerShell中通过以下方式获得的电流base64编码的证书!我已经开始认识到,我需要回避这个秘密,因为powershell API不是最简单易懂的--Certificate是一个陷阱:-)这有助于很好地解释事情! –