Sample code for 30+ languages & platforms
Go

Load PFX (PKCS#12) and List Certificates

See more Certificates Examples

Loads a PFX file (.pfx, .p12) and iterates over the certificates found within.

Chilkat Go Downloads

Go
    success := false

    certStore := chilkat.NewCertStore()

    pfxPath := "/Users/chilkat/testData/pfx/chilkat_ssl.pfx"
    pfxPassword := "test"
    success = certStore.LoadPfxFile(pfxPath,pfxPassword)
    if success != true {
        fmt.Println(certStore.LastErrorText())
        certStore.DisposeCertStore()
        return
    }

    numCerts := certStore.NumCertificates()

    fmt.Println("PFX contains ", numCerts, " certificates")

    cert := chilkat.NewCert()
    i := 0
    for i < numCerts {
        certStore.GetCert(i,cert)

        fmt.Println(i, ": (Common Name) ", cert.SubjectCN())
        fmt.Println(i, ": (Serial Number) ", cert.SerialNumber())
        fmt.Println(i, ": (Distinguished Name) ", cert.SubjectDN())

        i = i + 1
    }


    certStore.DisposeCertStore()
    cert.DisposeCert()