Sample code for 30+ languages & platforms
VB.NET Requires Chilkat v11.0.0+

Sign an email with a key in the Windows Current User certificate store

See more DKIM Examples

Run on Windows as the account that owns the signing certificate. Copy its thumbprint from Current User > Personal and supply it as hexadecimal digits. The thumbprint selects a certificate. The DKIM signature itself uses RSA-SHA256.

The certificate needs an accessible, exportable RSA private key for GetPrivateKey. Publish its matching public key under the selector in DNS. DKIM recipients use that DNS key to verify the message. An X.509 chain is unnecessary for this step.

Chilkat VB.NET Downloads

VB.NET
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim store As New Chilkat.CertStore
success = store.OpenCurrentUserStore(True)
If (success <> True) Then
    Debug.WriteLine(store.LastErrorText)
    Exit Sub
End If

Dim search As New Chilkat.JsonObject
search.UpdateString("thumbprint","YOUR_CERTIFICATE_THUMBPRINT")
Dim cert As New Chilkat.Cert
success = store.FindCert(search,cert)
If (success <> True) Then
    Debug.WriteLine(store.LastErrorText)
    Exit Sub
End If

If (cert.HasPrivateKey() <> True) Then
    Debug.WriteLine("The selected certificate has no accessible private key.")
    Exit Sub
End If

Dim privateKey As New Chilkat.PrivateKey
success = cert.GetPrivateKey(privateKey)
If (success <> True) Then
    Debug.WriteLine(cert.LastErrorText)
    Exit Sub
End If

Dim signer As New Chilkat.Dkim
signer.DkimDomain = "example.com"
signer.DkimSelector = "mail2026"
signer.DkimAlg = "rsa-sha256"
success = signer.SetDkimPrivateKey(privateKey)
If (success <> True) Then
    Debug.WriteLine(signer.LastErrorText)
    Exit Sub
End If

Dim message As New Chilkat.BinData
success = message.LoadFile("message.eml")
If (success <> True) Then
    Debug.WriteLine("Could not read message.eml.")
    Exit Sub
End If

success = signer.DkimSign(message)
If (success <> True) Then
    Debug.WriteLine(signer.LastErrorText)
    Exit Sub
End If

success = message.WriteFile("signed.eml")
If (success <> True) Then
    Debug.WriteLine("Could not write signed.eml.")
    Exit Sub
End If

Debug.WriteLine("Saved signed.eml.")