Android™ Requires Chilkat v11.0.0+
Android™
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 Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = 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.
CkPrivateKey privateKey = new CkPrivateKey();
success = privateKey.LoadAnyFormatFile("dkim-private.pem","");
if (success != true) {
Log.i(TAG, privateKey.lastErrorText());
return;
}
CkPublicKey publicKey = new CkPublicKey();
success = privateKey.ToPublicKey(publicKey);
if (success != true) {
Log.i(TAG, privateKey.lastErrorText());
return;
}
if (publicKey.keyType() != "rsa") {
Log.i(TAG, "Choose an RSA key for this rsa-sha256 example.");
return;
}
// false selects SubjectPublicKeyInfo. The p= value is base64 DER, on one line.
String pValue = publicKey.getEncoded(false,"base64");
if (pValue == "") {
Log.i(TAG, publicKey.lastErrorText());
return;
}
success = publicKey.SavePemFile(false,"dkim-public.pem");
if (success != true) {
Log.i(TAG, publicKey.lastErrorText());
return;
}
String selector = "mail2026";
String domain = "example.com";
Log.i(TAG, "TXT owner: " + selector + "._domainkey." + domain);
Log.i(TAG, "TXT value: v=DKIM1; k=rsa; p=" + pValue);
Log.i(TAG, "Saved dkim-public.pem.");
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}