我有一堆字符串和 pfx 证书,我想将它们存储在 Azure Key Vault 中,只有允许的用户/应用程序才能获取它们。将字符串存储为 Secret 并不难,但是如何以可以检索它并反序列化为证书的方式序列化证书?X509证书2 https://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2(v=vs.110).aspxC# 中的对象?
我尝试将其存储为密钥。这是Azure powershell代码
$securepfxpwd = ConvertTo-SecureString -String 'superSecurePassword' -AsPlainText -Force
$key = Add-AzureKeyVaultKey -VaultName 'UltraVault' -Name 'MyCertificate' -KeyFilePath 'D:\Certificates\BlaBla.pfx' -KeyFilePassword $securepfxpwd
但是当我试图得到它时异步获取Key https://msdn.microsoft.com/en-us/library/azure/mt134031.aspx方法,我无法使用它。
这是适合您的 PowerShell 脚本。替换文件路径、密码、保管库名称、机密名称。
$pfxFilePath = 'C:\mycert.pfx'
$pwd = '123'
$flag = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable
$collection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection
$collection.Import($pfxFilePath, $pwd, $flag)
$pkcs12ContentType = [System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12
$clearBytes = $collection.Export($pkcs12ContentType)
$fileContentEncoded = [System.Convert]::ToBase64String($clearBytes)
$secret = ConvertTo-SecureString -String $fileContentEncoded -AsPlainText –Force
$secretContentType = 'application/x-pkcs12'
Set-AzureKeyVaultSecret -VaultName 'myVaultName' -Name 'mySecretName' -SecretValue $Secret -ContentType $secretContentType
这是一个常见问题,因此我们将对其进行完善并作为帮助程序发布。
上面的脚本删除了密码,因为使用受密码保护的 PFX 然后将密码存储在其旁边是没有任何价值的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)