1 7 8 package org.enhydra.oyster.test; 9 10 import javax.mail.Transport ; 11 import org.enhydra.oyster.smime.SignedAndEnvelopedSMIME; 12 import org.enhydra.oyster.exception.SMIMEException; 13 import java.io.File ; 14 import java.io.ByteArrayInputStream ; 15 import java.io.InputStream ; 16 17 44 public class TestEncSigGeneratedHtml 45 { 46 47 public static void main(String [] args) 48 { 49 50 String subject = "S/MIME enveloped and signed message - Subject test: ÜüÄäÖöÜüß"; 51 String from = "sender@together.at"; 52 String password = "together"; 53 54 if (args.length < 8) 55 { 56 System.err.println( 57 System.getProperty("line.separator") + 58 "Usage of TestEncSigGeneratedHtml: " + 59 System.getProperty("line.separator") + 60 "java TestEncSigGeneratedHtml <mailHost> <mailAddress> <cerFileName> " + 61 "<algorithmName> <digestAlgorithm> <includingCert> <includingSignAttrib> " + 62 "<pfxFileName> [<attachment>]"+ 63 System.getProperty("line.separator") + 64 System.getProperty("line.separator") + 65 "Examples:" + 66 System.getProperty("line.separator") + 67 "java TestEncSigGeneratedHtml together.at recipient@together.at recipient512.cer " + 68 "RC240 SHA1_WITH_RSA true true sender512.pfx" + 69 System.getProperty("line.separator") + 70 "java TestEncSigGeneratedHtml together.at recipient@together.at recipient512.cer " + 71 "DES MD5_WITH_RSA true true sender512.pfx .\\test\\Zip8Test.zip"); 72 73 System.exit(-1); 74 } 75 76 String smtpHost = args[0]; 77 String addressTO = args[1]; 78 String cerFileName = args[2]; 79 String algorithmName = args[3]; 80 String digestAlgorithm = args[4]; 81 82 boolean includingCert = true; 83 if (args[5].equals("true")) 84 includingCert = true; 85 else 86 includingCert = false; 87 88 boolean includingSignAttrib = true; 89 if (args[6].equals("true")) 90 includingSignAttrib = true; 91 else 92 includingSignAttrib = false; 93 94 String pfxfileName = args[7]; 95 96 String fileName = null; 97 if (args.length > 8) 98 fileName = args[8]; 99 100 String addressCC = "recipient@together.at"; 101 String addressBCC = "recipient@together.at"; 102 103 subject = args[2] + " " + args[3] + " " + args[4] + " " + args[5] + " " + 104 args[6] + " " + args[7] + " " + subject; 105 106 SignedAndEnvelopedSMIME ess = null; 107 108 try { 109 ExampleGenerator generator = new ExampleGenerator(); 110 111 String green = "*****000generated.gif"; 116 117 File redFile = new File ("./test/pictures/red.gif"); 120 String red = redFile.getAbsoluteFile().getCanonicalPath(); 121 122 File blueFile = new File ("./test/pictures/blue.gif"); 125 String blue = "file:///" + blueFile.getAbsoluteFile().getCanonicalPath(); 126 blue = blue.replace('\\','/'); 127 128 String commonPath = new File ("./test/HtmlTest.html").getParent(); 135 136 generator.setResourceInExampleHtml("GREEN", green); 137 generator.setResourceInExampleHtml("RED", red); 138 generator.setResourceInExampleHtml("BLUE", blue); 139 140 InputStream [] in = {generator.getGifImage()}; 142 143 ess = new SignedAndEnvelopedSMIME(smtpHost, from, subject, "ISO-8859-1"); 145 146 ess.setContent( generator.getHtmlString(), "text/html", commonPath, in ); 148 152 ess.addAttachment(generator.getZipStream(), "test.zip"); 156 157 File attachment2 = new File ("./test/AdobeAcrobatTest.pdf"); 159 ess.addAttachment(attachment2); 160 File attachment3 = new File ("./test/Word2000Test.doc"); 161 ess.addAttachment(attachment3); 162 163 if (fileName!=null) { 164 ess.addAttachment(fileName); } 166 167 ess.setReply(from); 169 ess.addRecipient(addressTO, "TO", cerFileName); 173 ess.setCapabilities("SYMMETRIC", 5, 3, 1, 4, 2); ess.setCapabilities("ENCIPHER", 1, 0, 0, 0, 0); ess.setCapabilities("SIGNATURE", 3, 2, 1, 4, 0); 177 ess.addSigner(pfxfileName, password, digestAlgorithm, includingCert, includingSignAttrib); 178 179 if (algorithmName.equals("RC240")) 180 { 181 System.out.println("Creating enveloped and signed message with RC2 - 40 bits algorithm... "); 182 ess.signingAndEnveloping("ENCRYPT_FIRST"); } 185 else if (algorithmName.equals("RC264")) 186 { 187 System.out.println("Creating enveloped and signed message with RC2 - 64 bits algorithm... "); 188 ess.signingAndEnveloping(ess.RC2_CBC, 64, "ENCRYPT_FIRST"); } 190 else if (algorithmName.equals("RC2128")) 191 { 192 System.out.println("Creating enveloped and signed message with RC2 - 128 bits algorithm... "); 193 ess.signingAndEnveloping(ess.RC2_CBC, 128, "ENCRYPT_FIRST"); } 195 else if (algorithmName.equals("DES")) 196 { 197 System.out.println("Creating enveloped and signed message with DES algorithm... "); 198 ess.signingAndEnveloping(ess.DES, 56, "ENCRYPT_FIRST"); } 200 else if (algorithmName.equals("3DES")) 201 { 202 System.out.println("Creating enveloped and signed message with 3DES algorithm... "); 203 ess.signingAndEnveloping(ess.DES_EDE3_CBC, 192, "ENCRYPT_FIRST"); } 205 206 System.out.print("Sending enveloped and signed message ... "); 207 ess.send(); System.out.println("done."); 210 211 } 212 catch (Exception e) { 213 SMIMEException.setErrorFilePath("Log"); if(e instanceof SMIMEException) { 215 SMIMEException eTmp = (SMIMEException)e; 216 eTmp.displayErrors(null); 218 e = eTmp.getNonSMIMEException(); 219 if(e != null) 220 e.printStackTrace(); 221 } 222 else { 223 e.printStackTrace(); 224 } 225 } 226 } 227 } | Popular Tags |