【问题标题】:How to extract the blob from public certificate(.cer and .pfx) using azure powershell如何使用 azure powershell 从公共证书(.cer 和 .pfx)中提取 blob
【发布时间】:2020-01-24 19:29:35
【问题描述】:

我正在尝试使用 powershell 将公共和私有证书上传到 Azure Web 应用程序。我正在使用以下代码将证书上传到 webapp。我遇到的问题是如何使用 powershell 从证书文件(公共证书 .cer、私有证书 .pfx)中提取这些公共/私有证书元数据(blob 内容)和指纹。

$PropertiesObject = @{
    blob="LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUZ5RENDQTdDZ0F3SUJBZ0lDRUFBd0RRWUpLb1pJaHZjTkFRRUxCUUF3ZkRFTE1Ba0dBMVVFQmhNQ1ZWTXgKRlRBVEJnTlZCQWdNREZCbGJtNXplV3gyWVc1cFlURVRNQkVHQTFVRUJ3d0tVR2wwZEhOaWRYSm5hREVWTUJNRwpBMVVFQ2d3TVZHVnNaWFBDRVJUSUZJQ0FURS0tLS0tCg==";
    publicCertificateLocation= "CurrentUserMy"; 
    thumbprint= "8158F2A26BCB4A75479D2FBF17550";
    ResourceType = "Microsoft.Web/sites/publicCertificates";
    ResourceName= "DevUserService/my-cert-new"
}

$resourceId = '/subscriptions/967d-a594-8fd5-aeb26/resourceGroups/DevA_AppServices/providers/Microsoft.Web/sites/DevUserService'
$resource = Get-AzureRmResource -ResourceId $resourceId

New-AzureRmResource -Location $resource.Location -PropertyObject $PropertiesObject -ResourceGroupName $resource.ResourceGroupName -ResourceType Microsoft.Web/sites/publicCertificates -ResourceName "DevUserService/my-cert-new" -ApiVersion 2018-02-01 -Force

以上代码将公共证书上传并附加到 web 应用程序。

但我想使用 powershell 从系统中的 .cer、.pfx 文件中提取证书 blob 内容、指纹。

要试用代码,我已手动将此公共证书上传到我的 web 应用程序,下面的调用显示了 blob 内容。 Get-AzureRmResource -ResourceGroupName DevUS_A_ApplicationServices1 -ResourceType Microsoft.Web/sites/publicCertificates -ResourceName "DevService" -ApiVersion 2018-02-01

【问题讨论】:

    标签: certificate azure-web-app-service azure-powershell


    【解决方案1】:

    我解决了。这是读取 .cer 文件内容的代码。

    $fullpath = 'C:\Certs\mycert.cer' 
    $pwd = ConvertTo-SecureString -String 'anyPwd' -AsPlainText -Force
    $cert  = New-AzureRmApplicationGatewaySslCertificate -Name someCert -CertificateFile $fullpath -Password $pwd 
    
    $PropertiesObject = @{
            blob=$cert.Data; 
            publicCertificateLocation= "CurrentUserMy";
            thumbprint= $certThumbPrint;
            ResourceType = "Microsoft.Web/sites/publicCertificates"
        }
    

    我无法以这种方式读取指纹,但可以肯定的是,您可以将证书导入本地计算机并找到它。

    【讨论】:

      猜你喜欢
      • 2016-11-03
      • 1970-01-01
      • 2020-01-18
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-13
      • 2020-07-07
      相关资源
      最近更新 更多