PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
Verify the Authenticode Signature of an MSI, PowerShell, or VBScript File
See more Code Signing Examples
Demonstrates how to verify the Authenticode signature of a Windows Installer package (.msi), a PowerShell file (.ps1, .psm1, .psd1), or a VBScript file (.vbs), and how to get the certificate of the signer. Verifying these file types requires Chilkat v11.7.0 or later.Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
string ls_Path
oleobject loo_CodeSign
oleobject loo_SigInfo
long li_Valid
oleobject loo_SignerCert
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Starting in Chilkat v11.7.0, VerifySignature can verify the Authenticode signature of
// - Windows Installer packages (.msi)
// - PowerShell scripts, modules, and data files (.ps1, .psm1, .psd1)
// - VBScript files (.vbs)
// in addition to EXE and DLL files.
// This example verifies a signed PowerShell script.
// To verify an .msi or a .vbs, pass the path of that file instead.
ls_Path = "C:/someDir/Deploy.ps1"
loo_CodeSign = create oleobject
li_rc = loo_CodeSign.ConnectToNewObject("Chilkat.CodeSign")
if li_rc < 0 then
destroy loo_CodeSign
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_SigInfo = create oleobject
li_rc = loo_SigInfo.ConnectToNewObject("Chilkat.JsonObject")
// VerifySignature returns true if the file has a valid Authenticode signature.
// It returns false if the file is not signed, if the file was changed after it was signed,
// or if the signing certificate is not trusted.
li_Valid = loo_CodeSign.VerifySignature(ls_Path,loo_SigInfo)
if li_Valid = 0 then
// The LastErrorText explains why the verification failed.
Write-Debug loo_CodeSign.LastErrorText
destroy loo_CodeSign
destroy loo_SigInfo
return
end if
Write-Debug "The Authenticode signature is valid."
// The details of the signature are returned in the JSON, in the same layout as for an EXE or DLL.
// See Verify Authenticode Signature of EXE or DLL for a sample of the JSON and code that parses it.
Write-Debug "signing algorithm: " + loo_SigInfo.StringOf("pkcs7.verify.signerInfo[0].signingAlgName")
Write-Debug "hash algorithm: " + loo_SigInfo.StringOf("pkcs7.verify.signerInfo[0].cert.digestAlgName")
// Get the certificate of the signer.
// The signer certificate is available only after a call to VerifySignature that returned true.
// It is the public certificate only. It does not include the signer's private key.
loo_SignerCert = create oleobject
li_rc = loo_SignerCert.ConnectToNewObject("Chilkat.Cert")
li_Success = loo_CodeSign.GetSignerCert(loo_SignerCert)
if li_Success = 0 then
Write-Debug loo_CodeSign.LastErrorText
destroy loo_CodeSign
destroy loo_SigInfo
destroy loo_SignerCert
return
end if
Write-Debug "signed by: " + loo_SignerCert.SubjectCN
Write-Debug "certificate issued by: " + loo_SignerCert.IssuerCN
Write-Debug "certificate serial number: " + loo_SignerCert.SerialNumber
Write-Debug "certificate valid until: " + loo_SignerCert.ValidToStr
destroy loo_CodeSign
destroy loo_SigInfo
destroy loo_SignerCert