Powershell生成的pfx文件密码问题

时间:2019-11-13 09:08:40

标签: uwp pfx

我遵循msdn article使用powershell生成pfx文件。所以我已经顺序执行

let newState = {
    ...state,
    items: {
        ...state.items,
        'item-1': {
            ...state.items['item-1'],
            task: [...state.items['item-1'].task, newTask]
        }
    }
};

到目前为止,一切都很好,但是当我尝试使用下面的comman获得pfx证书时。它提示输入我使用的密码。我正在尝试使用与“ mypassword”完全相同的密码,但是它在下面返回错误

let state = {
    items: {
      'item-1': {
        id: 'item-1',
        title: 'To do',
        task: ['task-1', 'task-2', 'task-3', 'task-4']
      },
      'item-2': {
        id: 'item-2',
        title: 'In progress',
        task: []
      },
    }
};

let newTask = "task-4";

let newState = {
    ...state,
    items: {
        ...state.items,
        'item-1': {
            ...state.items['item-1'],
            task: [...state.items['item-1'].task, newTask]
        }
    }
};

console.log(newState);
  

Get-PfxCertificate:指定的网络密码不正确。在   行:1字符:1

我正在尝试使用此证书和密码在azure devops上创建构建管道,但是azurepipelines会给我同样的错误消息。

如果我使用Visual Studio 2019创建pfx文件,则使用我提供的密码获取Get-PfxCertificate效果很好。但是Azure管道返回了另一个错误。

我的问题是

  1. 使用Visual Studio 2019与PowerShell创建pfx文件有什么区别?为什么VS 2019生成的pfx无法正常工作。

  2. 为什么Get-PfxCertificate不接受我用来生成的密码?

关于第二个问题,我认为这可能与纯文本vs SecureString有关。这就是为什么我尝试使用以下命令以及docs中所述的原因。它告诉我-password无法识别。

pasv_min_port=40000
pasv_max_port=50000

错误:

New-SelfSignedCertificate -Type Custom -Subject "CN=Contoso Software, O=Contoso Corporation, C=US" -KeyUsage DigitalSignature -FriendlyName "Your friendly name goes here" -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}")

$pwd = ConvertTo-SecureString -String mypassword -Force -AsPlainText 
Export-PfxCertificate -cert "Cert:\CurrentUser\My\<Certificate Thumbprint>" -FilePath mycert.pfx -Password $pwd

3 个答案:

答案 0 :(得分:1)

  1. 据我所知,应该没有太大的区别,但是老实说,我不确定在VS中是如何做到的

  2. 仅在PS版本6.1+中添加了Get-PFXCertificate cmdlet的“ -Password”参数,可能是因为我在本地遇到相同的问题,并且是因为我在5.1上,所以请检查您在Azure中使用的版本

答案 1 :(得分:0)

我不知道1,但是对于2,您不应该对-Password命令使用大写字母P吗?请参阅Powershell page: Get-Pfx​Certificate供参考,其中指出以下内容;

Get-PfxCertificate
   -LiteralPath <String[]>
   [-Password <SecureString>]
   [-NoPromptForPassword]
   [<CommonParameters>]

如果问题仍然存在,显然还有其他事情在发生,但是我会先尝试一下,看看是否可能因为这个原因而无法识别该命令。

答案 2 :(得分:0)

我只想为遇到我遇到的这个愚蠢问题的其他人提供答案。如果您在 powershell 中使用 $ 之类的符号而不使用撇号或双引号,则生成仍然有效并且您获得 pfx 文件但密码与您设置的不同:) 这就是 azure devops 返回此错误的原因