|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object iaik.utils.SmtpMailer iaik.smime.SMimeMailer
public class SMimeMailer
Simple S/MIME mailing tool based on the IAIK-JCE SmtpMailer utility. It may be used for sending signed, encrypted, or signed and encrypted text mails without usage of the JavaMail API. Only the application/pkcs7-mime type is used for both, signed (smime-type "signed-data") or encrypted (smime-type "enveloped-data") mails.
The following example shows how to use this class for sending a
// mailhost String mailhost = "mailhost"; // sender name String senderName = "John Doe"; // sender address String senderAddress = "John.Doe@test.at"; // certificate list to be included into the SignedData X509Certificate[] certificates = ...; // certificate of the signer X509Certificate senderCertificate = ...; // encryption cert of sender (if to be included into the certificates field) X509Certificate encryptionCertOfSender = ...; // the private signer key PrivateKey signerKey = ...; // create a SMimeMailer SMimeMailer mailer = new SMimeMailer(mailhost, SMimeMailer.SIGNED); // set subject header mailer.setSubject("..."); // sending date is now mailer.addDate(); // set sender (signer) information mailer.setFrom(senderName, senderAddress, certificates, signerCertificate, encryptionCertOfSender, null, signerKey, AlgorithmID.sha256, AlgorithmID.rsaEncryption); // set recipient name and recipient address String recipientName = ...; String recipientAddress = ...; mailer.addTo(recipientName, recipientAddress); // set the message text mailer.addText(...); // send mail mailer.sendMail();
// mailhost String mailhost = "mailhost"; // sender name String senderName = "John Doe"; // sender address String senderAddress = "John.Doe@test.at"; // encryption cert of sender (to encrypt the symmetric key for the sender, too) X509Certificate encryptionCertOfSender = ...; // key encryption algorithm for encrypting the symmetric key for the sender AlgorithmID keyEncAlgOfSender = AlgorithmID.rsaEncryption; // create a SMimeMailer SMimeMailer mailer = new SMimeMailer(mailhost, SMimeMailer.ENCRYPTED); // set subject header mailer.setSubject("..."); // sending date is now mailer.addDate(); // set sender information mailer.setFrom(senderName, senderAddress, encryptionCertOfSender, keyEncAlgOfSender); // encryption cert of the recipient X509Certificate recipientCert = ...; // key encryption algorithm for encrypting the symmetric key for the recipient AlgorithmID keyEncAlgOfRecipient = AlgorithmID.rsaEncryption; // set recipient information String recipientName = ...; String recipientAddress = ...; mailer.addTo(recipientName, recipientAddress, recipientCert, keyEncAlgOfRecipient); // set encryption algorithm information AlgorithmID contentEA = (AlgorithmID)AlgorithmID.aes256_CBC.clone(); int keyLength = 256; mailer.setEncryption(contentEA, keyLength); // set the message text mailer.addText(...); // send mail mailer.sendMail();
// mailhost String mailhost = "mailhost"; // sender name String senderName = "John Doe"; // sender address String senderAddress = "John.Doe@test.at"; // certificate list to be included into the SignedData X509Certificate[] certificates = ...; // certificate of the signer X509Certificate signerCertificate = ...; // encryption cert of signer (to encrypt the symmetric key for the sender, too) X509Certificate encryptionCertOfSender = ...; // key encryption algorithm for encrypting the symmetric key for the sender (signer) AlgorithmID keyEncAlgOfSender = AlgorithmID.rsaEncryption; // the private signer key PrivateKey signerKey = ...; // create a SMimeMailer SMimeMailer mailer = new SMimeMailer(mailhost, SMimeMailer.SIGNED_AND_ENCRYPTED); // set subject header mailer.setSubject("..."); // sending date is now mailer.addDate(); // set sender (signer) information mailer.setFrom(senderName, senderAddress, certificates, signerCertificate, encryptionCertOfSender, keyEncAlgOfSender, signerKey, AlgorithmID.sha256, AlgorithmID.rsaEncryption); // encryption cert of the recipient X509Certificate recipientCert = ...; // key encryption algorithm for encrypting the symmetric key for the recipient AlgorithmID keyEncAlgOfRecipient = AlgorithmID.rsaEncryption; // set recipient information String recipientName = ...; String recipientAddress = ...; mailer.addTo(recipientName, recipientAddress, recipientCert, keyEncAlgOfRecipient); // set encryption algorithm information AlgorithmID contentEA = (AlgorithmID)AlgorithmID.aes256_CBC.clone(); int keyLength = 256; mailer.setEncryption(contentEA, keyLength); // set the message text mailer.addText(...); // send mail mailer.sendMail();
Field Summary | |
---|---|
static int |
ENCRYPTED
Value for creating encrypted S/MIME messages. |
static int |
SIGNED
Value for creating signed S/MIME messages. |
static int |
SIGNED_AND_ENCRYPTED
Value for creating signed and encrypted S/MIME messages. |
Constructor Summary | |
---|---|
SMimeMailer(java.lang.String mailhost,
int mode)
Creates a new SMimeMailer. |
Method Summary | |
---|---|
void |
addAdditionalField(java.lang.String line)
Sets any additional field according to RFC822. |
void |
addBcc(java.lang.String realName,
java.lang.String emailAddress,
X509Certificate recipientCert,
AlgorithmID keyEncAlg)
Adds one receiver (Bcc: field) of the S/MIME email message. |
void |
addCc(java.lang.String realName,
java.lang.String emailAddress,
X509Certificate recipientCert,
AlgorithmID keyEncAlg)
Adds one receiver (Cc: field) of the S/MIME email message. |
void |
addDate()
Sets the "Date:" field to the current date. |
void |
addDate(java.util.Date date)
Sets the "Date:" field to the specified date. |
void |
addTo(java.lang.String realName,
java.lang.String emailAddress,
X509Certificate recipientCert,
AlgorithmID keyEncAlg)
Adds one receiver (To: field) of the S/MIME email message. |
boolean |
sendMail()
Encrypt and send the mail that was just created. |
void |
setEncryption(AlgorithmID contentEncAlg,
int keyLength)
Sets the symmetric algorithm for encrypting the message. |
void |
setFrom(java.lang.String realName,
java.lang.String emailAddress,
X509Certificate[] certificates,
X509Certificate signerCertificate,
X509Certificate encryptionCertOfSender,
AlgorithmID keyEncAlg,
java.security.PrivateKey signerKey,
AlgorithmID hashAlgorithm,
AlgorithmID signatureAlgorithm)
Sets the from field of the S/MIME email message. |
void |
setFrom(java.lang.String realName,
java.lang.String emailAddress,
X509Certificate senderCert,
AlgorithmID keyEncAlg)
Sets the from field of the S/MIME email message. |
void |
setSecureRandom(java.security.SecureRandom random)
Sets the source of randomness for the key generation. |
java.lang.String |
toString()
Returns a string representation of this SMimeMailer. |
Methods inherited from class iaik.utils.SmtpMailer |
---|
addBcc, addCc, addText, addTo, checkResponse, send, sendCommands, setDebug, setFrom, setLineSeparator, setReplyTo, setSender, setSubject, setText, setVerify, writeBody, writeHeaders |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int ENCRYPTED
public static final int SIGNED
public static final int SIGNED_AND_ENCRYPTED
Constructor Detail |
---|
public SMimeMailer(java.lang.String mailhost, int mode)
mailhost
- the name of the SMTP server (e.g. "mailhost.domain.com")mode
- the S/MIME message mode (ENCRYPTED
,
SIGNED
, or
SIGNED_AND_ENCRYPTED
)Method Detail |
---|
public void setFrom(java.lang.String realName, java.lang.String emailAddress, X509Certificate senderCert, AlgorithmID keyEncAlg)
void setFrom(String realName, String emailAddress);
from the superclass SmtpMailer.
realName
- the real name of the sender (e.g. "John Doe")emailAddress
- the email address of the sender (e.g. "John.Doe@test.at")senderCert
- the certificate of the senderkeyEncAlg
- the algorithm used to encrypt the temporary symmetric key for the senderpublic void setFrom(java.lang.String realName, java.lang.String emailAddress, X509Certificate[] certificates, X509Certificate signerCertificate, X509Certificate encryptionCertOfSender, AlgorithmID keyEncAlg, java.security.PrivateKey signerKey, AlgorithmID hashAlgorithm, AlgorithmID signatureAlgorithm) throws SMimeException
realName
- the real name of the sender (e.g. "John Doe")emailAddress
- the email address of the sender (e.g. "John.Doe@test.at")certificates
- the certificates to be set for the SignedData signature object
(may also contain the encryption cert of the sender)signerCertificate
- the certificate of the signer (sender)encryptionCertOfSender
- the encryption cert of the sender (if to be
included into the certificates field and/or the
message should be encrypted for the sender, too; otherwise null
)keyEncAlg
- the algorithm used to encrypt the temporary symmetric key for the sender
(if the message should be encrypted, too; otherwise null
)signerKey
- the private key of the sender used for signing the messagehashAlgorithm
- the hash algorithm to be use (e.g. AlgorithmID.sha256)signatureAlgorithm
- the signature algorithm to be used (e.g. AlgorithmID.rsaEncryption)
SMimeException
- if the signer setup failspublic void addTo(java.lang.String realName, java.lang.String emailAddress, X509Certificate recipientCert, AlgorithmID keyEncAlg)
realName
- the real name of the sender (e.g. "John Doe")emailAddress
- the email address of the sender (e.g. "John.Doe@test.at")recipientCert
- the certificate of the senderkeyEncAlg
- the algorithm used to encrypt the temporary symmetric key for a receiverpublic void addCc(java.lang.String realName, java.lang.String emailAddress, X509Certificate recipientCert, AlgorithmID keyEncAlg)
realName
- the real name of the sender (e.g. "John Doe")emailAddress
- the email address of the sender (e.g. "John.Doe@test.at")recipientCert
- the certificate of the senderkeyEncAlg
- the algorithm used to encrypt the temporary symmetric key for a receiverpublic void addBcc(java.lang.String realName, java.lang.String emailAddress, X509Certificate recipientCert, AlgorithmID keyEncAlg)
realName
- the real name of the sender (e.g. "John Doe")emailAddress
- the email address of the sender (e.g. "John.Doe@test.at")recipientCert
- the certificate of the senderkeyEncAlg
- the algorithm used to encrypt the temporary symmetric key for a receiverpublic void addAdditionalField(java.lang.String line)
addAdditionalField
in class SmtpMailer
line
- a complete linepublic void addDate()
public void addDate(java.util.Date date)
date
- the datepublic void setEncryption(AlgorithmID contentEncAlg, int keyLength)
Examples for possible encryption algorithms are:
contentEncAlg
- the algorithm for encrypting the contentkeyLength
- the key length for RC2public void setSecureRandom(java.security.SecureRandom random)
random
- a random number generatorpublic boolean sendMail() throws SmtpException
sendMail
in class SmtpMailer
SmtpException
- if there is a problem while sending the EMailSmtpMailer
public java.lang.String toString()
toString
in class SmtpMailer
|
This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |