Sample code for 30+ languages & platforms
PowerBuilder

X509Certificate GetCertHash SHA256

See more Certificates Examples

Shows how to get the SHA256 hash of a certificate.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Cert
oleobject loo_BdDer
string ls_CertHash

li_Success = 0

loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
if li_rc < 0 then
    destroy loo_Cert
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Load a certificate object with a certificate.
// The certificate object could have come from any source,
// or perhaps was obtained from another Chilkat function.
// The source does not matter.  What matters is that we have
// a cert object loaded with the certificate..
li_Success = loo_Cert.LoadFromFile("qa_data/certs/cert_test123.cer")
if li_Success <> 1 then
    Write-Debug loo_Cert.LastErrorText
    destroy loo_Cert
    return
end if

// Get the binary DER of the certificae, and compute the SHA256 hash:
loo_BdDer = create oleobject
li_rc = loo_BdDer.ConnectToNewObject("Chilkat.BinData")

loo_Cert.ExportCertDerBd(loo_BdDer)

// Get the base64 representation of the SHA256 hash.
ls_CertHash = loo_BdDer.GetHash("sha256","base64")

Write-Debug "Certificate hash in base64 = " + ls_CertHash


destroy loo_Cert
destroy loo_BdDer