操作环境:Windows PowerShell(管理员)
创建证书
$params = @{
Type = 'CodeSigningCert'
Subject = 'CN=名字,E =邮箱'
TextExtension = @(
'2.5.29.37={text}1.3.6.1.5.5.7.3.3',
'2.5.29.17={text}upn=pattifuller@contoso.com' )
KeyAlgorithm = 'RSA'
KeyLength = 2048
CertStoreLocation = 'Cert:\LocalMachine\My'
}
New-SelfSignedCertificate @params
2.5.29.37
:代表证书用途。1.3.6.1.5.5.7.3.3
:代表用途为代码签名。Cert:\LocalMachine\My
:使用证书驱动器/本地计算机/个人
信任证书
# 获取证书对象
$cert = Get-ChildItem Cert:\LocalMachine\My -CodeSigningCert
# 创建一个本地计算机的root的X509证书存储区域对象。
$rootStore= New-Object system.security.cryptography.X509Certificates.x509Store("root","LocalMachine")
# 打开写入流
$rootStore.Open("ReadWrite")
# 将要信任的证书写入
$rootStore.Add($cert) #证书对象
# 关闭流
$rootStore.Close()
签名
# 获取证书对象
$cert = Get-ChildItem Cert:\LocalMachine\My -CodeSigningCert
# 签名
Set-AuthenticodeSignature .\vue.ps1 $cert