1 7 8 package org.enhydra.oyster.test; 9 10 import org.enhydra.oyster.smime.SignedSMIME; 11 import org.enhydra.oyster.exception.SMIMEException; 12 import javax.mail.Transport ; 13 import java.io.FileInputStream ; 14 import java.io.File ; 15 16 39 public class TestSignedHtml 40 { 41 42 public static void main(String [] args) 43 { 44 String subject = "S/MIME signed message - Subject test: ÜüÄäÖöÜüß"; 45 String from = "sender@together.at"; 46 String password = "together"; 47 48 if (args.length < 7) 49 { 50 System.err.println( 51 System.getProperty("line.separator") + 52 "Usage of TestSignedHtml: " + 53 System.getProperty("line.separator") + 54 "java TestSignedHtml <mailHost> <mailAddress> <digestAlgorithm> " + 55 "<includingCert> <includingSignAttrib> <pfxFileName> <externalSigning>" + 56 "[<attachment>]" + 57 System.getProperty("line.separator") + 58 System.getProperty("line.separator") + 59 "Examples:" + 60 System.getProperty("line.separator") + 61 "java TestSignedHtml together.at recipient@together.at SHA1_WITH_RSA true " + 62 "true sender512.pfx true"+ 63 System.getProperty("line.separator") + 64 "java TestSignedHtml together.at recipient@together.at SHA1_WITH_DSA true " + 65 "true senderDSA512.pfx false .\\test\\Zip8Test.zip"); 66 System.exit(-1); 67 } 68 69 String smtpHost = args[0]; 70 String addressTO = args[1]; 71 String digestAlgorithm = args[2]; 72 73 boolean includingCert = true; 74 if (args[3].equalsIgnoreCase("true")) 75 includingCert = true; 76 else 77 includingCert = false; 78 79 boolean includingSignAttrib = true; 80 if (args[4].equalsIgnoreCase("true")) 81 includingSignAttrib = true; 82 else 83 includingSignAttrib = false; 84 85 String pfxfileName = args[5]; 86 87 boolean externalSigning = true; 88 if (args[6].equalsIgnoreCase("true")) 89 externalSigning = true; 90 else 91 externalSigning = false; 92 93 String fileName = null; 94 if (args.length > 7) 95 fileName = args[7]; 96 97 String addressCC = "recipient@together.at"; 98 String addressBCC = "recipient@together.at"; 99 100 subject = digestAlgorithm + " " + args[3] + " " + args[4] + " " + 101 pfxfileName + " " + args[6] + " " + subject; 102 103 File htmlContent = new File ("./test/HtmlTest.html"); 104 105 SignedSMIME ss = null; 106 107 try { 108 109 ss = new SignedSMIME(smtpHost, from, subject, "ISO-8859-1"); 111 112 ss.setContent(htmlContent,"text/html"); 114 118 122 if (fileName!=null) { 123 ss.addAttachment(fileName); } 125 126 ss.setReply(from); 128 ss.addRecipient(addressTO, "TO"); 132 ss.setCapabilities("SYMMETRIC", 5, 3, 1, 4, 2); ss.setCapabilities("ENCIPHER", 1, 0, 0, 0, 0); ss.setCapabilities("SIGNATURE", 1, 2, 3, 4, 0); 136 ss.addSigner(pfxfileName, password, digestAlgorithm, 137 includingCert, includingSignAttrib); 139 System.out.println("Creating signed message with " + digestAlgorithm + " algorithm ... "); 140 ss.signing(externalSigning); 141 System.out.print("Sending signed message ... "); 142 ss.send(); System.out.println("done."); 145 } 146 catch (Exception e) { 147 SMIMEException.setErrorFilePath("Log"); if(e instanceof SMIMEException) { 149 SMIMEException eTmp = (SMIMEException)e; 150 eTmp.displayErrors(null); 152 e = eTmp.getNonSMIMEException(); 153 if(e != null) 154 e.printStackTrace(); 155 } 156 else { 157 e.printStackTrace(); 158 } 159 } 160 } 161 } | Popular Tags |