我已经使用 Azure 门户中的 RunAs 帐户创建了一个自动化帐户。证书已自动生成。我想使用 openssl 实用程序从此证书创建一个 PFX 文件。
我可以通过以下步骤和代码使用 PowerShell Core 7.1.0-rc.2 来做到这一点:
- Azure 门户 > Azure Active Directory > 应用注册 > 自动化帐户的服务主体
- 从左侧菜单中选择 Manifest,在 JSON 中向下滚动到“keyCredentials”部分
- 将“value”属性的整个字符串复制到 PowerShell 中的变量:
$base64value = "<contents of the value property here>"
- 创建 PFX 文件的 PowerShell 代码:
# Create a X509 certificate object
$byteArray = [System.Convert]::FromBase64String($base64value)
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($byteArray)
# Export the certificate as a PFX file
$bytesPfx = $cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx)
[System.IO.File]::WriteAllBytes('filename.pfx', $bytesPfx)
鉴于自动化帐户的 JSON 清单中的 base64 字符串值,我想要弄清楚的是如何使用 openssl 实用程序执行相同的过程。由于我能够将该 base64 字符串转换为字节数组,然后使用 .NET 类的构造函数转换为 X509 证书,我想我需要使用 openssl x509,但我找不到任何采用 base64 的选项字符串或二进制参数或文件。