Sample code for 30+ languages & platforms
PowerBuilder

Cache a DKIM Public Key from a File

See more DKIM / DomainKey Examples

Demonstrates the Chilkat Dkim.LoadPublicKeyFile method, which caches an RSA public key read from a local file for a specific selector and domain. The arguments are the selector, the domain, and the public-key file path. Supported formats include PEM X.509 SubjectPublicKeyInfo and PEM PKCS#1 RSA public key.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: This is the file-based form of LoadPublicKey, convenient when the key already lives in a .pem file — a saved copy of what the domain publishes in DNS. As with the string form, the cache is keyed on the exact selector and domain, so those must match the signature being verified. Pre-loading keys this way lets a verifier work without any DNS access at all.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Dkim

li_Success = 0

//  Demonstrates the Dkim.LoadPublicKeyFile method, which caches an RSA public key read from a
//  local file for a specific selector and domain.  The 1st argument is the selector, the 2nd is
//  the domain, and the 3rd is the local public-key file path.

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

//  Read the public key from a file and cache it under the exact selector and domain.  Supported
//  formats include PEM X.509 SubjectPublicKeyInfo and PEM PKCS#1 RSA public key.
li_Success = loo_Dkim.LoadPublicKeyFile("myselector","example.com","qa_data/dkim_public.pem")
if li_Success = 0 then
    Write-Debug loo_Dkim.LastErrorText
    destroy loo_Dkim
    return
end if

Write-Debug "Public key loaded and cached."


destroy loo_Dkim