如何通过检索Azure Key Vault证书执行代码签名?

gzjq41n4  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(115)

我正在尝试使用PowerShell检索Azure密钥库证书以执行代码签名。

$pfxSecret = Get-AzKeyVaultSecret -VaultName kv -Name CodeSigning -AsPlainText
$secretByte = [Convert]::FromBase64String($pfxSecret)
$x509Cert = New-Object Security.Cryptography.X509Certificates.X509Certificate2
$x509Cert.Import($secretByte, $null, [Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$pfxFileByte = $x509Cert.Export([Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12, $password)

Set-AuthenticodeSignature -FilePath C:\Users\Desktop\*.dll $pfxFileByte -TimestampServer http://timestamp.digicert.com
```.

字符串
是否有其他方法可以检索Azure密钥库证书并执行代码签名?

c3frrgcw

c3frrgcw1#

错误消息:

Set-AuthenticodeSignature : Cannot convert 'System.Byte[]' to the type 'System.Security.Cryptography.X509Certificates.X509Certificate2' required by parameter 'Certificate'. Specified method is not supported.

字符串
告诉你绑定到-Certificate参数的参数是[byte[]]类型-这意味着它是一个字节数组-并且PowerShell的参数绑定器无法将其转换为[509Certificate2]类型的对象。
$pfxFileBytes是唯一一个没有显式指定参数名的参数,因此可以假定该参数是有问题的参数。
因为你已经有了所需格式的证书,存储在$x509Cert中,所以传递它:

Set-AuthenticodeSignature -FilePath C:\Users\Desktop\*.dll -Certificate $x509Cert -TimestampServer http://timestamp.digicert.com

相关问题