VB.NET Requires Chilkat v11.0.0+
VB.NET
Prepare a DKIM public key and DNS TXT record
See more DKIM Examples
Start with an RSA signing key in dkim-private.pem. This writes its public half to dkim-public.pem for local testing and prints the TXT record to enter at your DNS provider. Keep the private PEM on the signer. Use a 2048-bit or larger RSA key for a new deployment. DKIM RSA key sizes.
Use your signing domain and selector in place of example.com and mail2026. A provider that appends the zone usually wants just mail2026._domainkey as the name. If the value exceeds 255 bytes, split it into adjacent character strings within one TXT record. DNS joins those strings without adding spaces. Publish a new selector before rotating keys and keep the old record while previously signed mail is still in transit.
Chilkat VB.NET Downloads
Dim success As Boolean = False
' Assumes Chilkat is unlocked. See Global Unlock Sample.
' Supply your RSA signing key. For an encrypted PEM, get its password from your credential store.
Dim privateKey As New Chilkat.PrivateKey
success = privateKey.LoadAnyFormatFile("dkim-private.pem","")
If (success <> True) Then
Debug.WriteLine(privateKey.LastErrorText)
Exit Sub
End If
Dim publicKey As New Chilkat.PublicKey
success = privateKey.ToPublicKey(publicKey)
If (success <> True) Then
Debug.WriteLine(privateKey.LastErrorText)
Exit Sub
End If
If (publicKey.KeyType <> "rsa") Then
Debug.WriteLine("Choose an RSA key for this rsa-sha256 example.")
Exit Sub
End If
' false selects SubjectPublicKeyInfo. The p= value is base64 DER, on one line.
Dim pValue As String = publicKey.GetEncoded(False,"base64")
If (pValue = "") Then
Debug.WriteLine(publicKey.LastErrorText)
Exit Sub
End If
success = publicKey.SavePemFile(False,"dkim-public.pem")
If (success <> True) Then
Debug.WriteLine(publicKey.LastErrorText)
Exit Sub
End If
Dim selector As String = "mail2026"
Dim domain As String = "example.com"
Debug.WriteLine("TXT owner: " & selector & "._domainkey." & domain)
Debug.WriteLine("TXT value: v=DKIM1; k=rsa; p=" & pValue)
Debug.WriteLine("Saved dkim-public.pem.")