Class DkimSigner
java.lang.Object
com.codename1.backend.mail.DkimSigner
Signs outgoing mail with DKIM (RFC 6376): rsa-sha256, relaxed header and
relaxed body canonicalization.
The receiver finds the public key in DNS, in a TXT record at
<selector>._domainkey.<domain>. Publish it before turning signing on.
With cn1.mail.dkim.domain, cn1.mail.dkim.selector and
cn1.mail.dkim.privateKey set, every mail Mailers sends is signed, over
SMTP and SES alike. The key is PEM text or the path of a PEM file.
DkimSigner signer = new DkimSigner("example.com", "mail", pem);
byte[] signed = signer.sign(message);
-
Constructor Summary
ConstructorsConstructorDescriptionDkimSigner(String domain, String selector, String pemPrivateKey) A signer fordomainwhose public key is published underselector.DkimSigner(String domain, String selector, String pemPrivateKey, String[] headers) A signer that signs the named headers, the ones present, in this order. -
Method Summary
Modifier and TypeMethodDescriptionstatic DkimSignerconfigured(String domain, String selector, String key) The signer thecn1.mail.dkim.*settings describe, or null when none of them is set.The domain mail is signed for, thed=tag.The selector, thes=tag.byte[]sign(byte[] rawMessage) rawMessagewith a DKIM-Signature header in front of it.
-
Constructor Details
-
DkimSigner
A signer fordomainwhose public key is published underselector.- Parameters:
domain- the signing domain, thed=tagselector- the key's selector, thes=tagpemPrivateKey- an RSA private key in PEM, PKCS#8 or PKCS#1- Throws:
IOException- when the key cannot be read
-
DkimSigner
public DkimSigner(String domain, String selector, String pemPrivateKey, String[] headers) throws IOException A signer that signs the named headers, the ones present, in this order.- Parameters:
domain- the signing domain, thed=tagselector- the key's selector, thes=tagpemPrivateKey- an RSA private key in PEM, PKCS#8 or PKCS#1headers- the names of the headers to sign- Throws:
IOException- when the key cannot be read
-
-
Method Details
-
configured
The signer thecn1.mail.dkim.*settings describe, or null when none of them is set.- Parameters:
domain-cn1.mail.dkim.domainselector-cn1.mail.dkim.selectorkey-cn1.mail.dkim.privateKey: PEM text, or the path of a PEM file- Returns:
- the signer, or null
- Throws:
IOException- when only some of the three are set, or the key cannot be read
-
getDomain
-
getSelector
-
sign
rawMessagewith a DKIM-Signature header in front of it. The message must use CRLF line ends, asMimeWriterwrites them.- Parameters:
rawMessage- the message as it will be sent- Returns:
- the signed message
- Throws:
IOException- when signing fails
-