1

我已经使用 Azure 门户中的 RunAs 帐户创建了一个自动化帐户。证书已自动生成。我想使用 openssl 实用程序从此证书创建一个 PFX 文件。

我可以通过以下步骤和代码使用 PowerShell Core 7.1.0-rc.2 来做到这一点:

  1. Azure 门户 > Azure Active Directory > 应用注册 > 自动化帐户的服务主体
  2. 从左侧菜单中选择 Manifest,在 JSON 中向下滚动到“keyCredentials”部分
  3. 将“value”属性的整个字符串复制到 PowerShell 中的变量:
    $base64value = "<contents of the value property here>"
  4. 创建 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 的选项字符串或二进制参数或文件。

4

1 回答 1

0

好的,谢谢@bartonjs 的提示。我最终从 Linux shell 执行此操作:

echo "<huge base64-encoded string from value property>" > base64.data.txt
base64 --decode base64.data.txt > test01.pfx

然后我测试了使用该 PFX 文件调用 X509Certificate2 类的 .NET 构造函数,它成功创建了证书对象。

于 2020-10-23T19:49:04.623 回答