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 TestSigEncGeneratedHtml 45 { 46 47 public static void main(String [] args) 48 { 49 50 String subject = "S/MIME signed and enveloped message - Subject test: ÜüÄäÖöÜüß"; 51 String content = "S/MIME signed and enveloped message example\r\nContent test: ÜüÄäÖöÜüß!"; 52 String from = "sender@together.at"; 53 String password = "together"; 54 55 if (args.length < 8) 56 { 57 System.err.println( 58 System.getProperty("line.separator") + 59 "Usage of TestSigEncGeneratedHtml: " + 60 System.getProperty("line.separator") + 61 "java TestSigEncGeneratedHtml <mailHost> <mailAddress> <cerFileName> " + 62 "<algorithmName> <digestAlgorithm> <includingCert> <includingSignAttrib> " + 63 "<pfxFileName> [<attachment>]"+ 64 System.getProperty("line.separator") + 65 System.getProperty("line.separator") + 66 "Examples:" + 67 System.getProperty("line.separator") + 68 "java TestSigEncGeneratedHtml together.at recipient@together.at recipient512.cer " + 69 "RC240 SHA1_WITH_RSA true true sender512.pfx" + 70 System.getProperty("line.separator") + 71 "java TestSigEncGeneratedHtml together.at recipient@together.at recipient512.cer " + 72 "DES MD5_WITH_RSA true true sender512.pfx .\\test\\Zip8Test.zip"); 73 System.exit(-1); 74 75 System.exit(-1); 76 } 77 78 79 String smtpHost = args[0]; 80 String addressTO = args[1]; 81 String cerFileName = args[2]; 82 String algorithmName = args[3]; 83 String digestAlgorithm = args[4]; 84 85 boolean includingCert = true; 86 if (args[5].equals("true")) 87 includingCert = true; 88 else 89 includingCert = false; 90 91 boolean includingSignAttrib = true; 92 if (args[6].equals("true")) 93 includingSignAttrib = true; 94 else 95 includingSignAttrib = false; 96 97 String pfxfileName = args[7]; 98 99 String fileName = null; 100 if (args.length > 8) 101 fileName = args[8]; 102 103 String addressCC = "recipient@together.at"; 104 String addressBCC = "recipient@together.at"; 105 106 subject = args[2] + " " + args[3] + " " + args[4] + " " + args[5] + " " + 107 args[6] + " " + args[7] + " " + subject; 108 109 SignedAndEnvelopedSMIME see = null; 110 111 try { 112 ExampleGenerator generator = new ExampleGenerator(); 113 114 String green = "*****000generated.gif"; 119 120 File redFile = new File ("./test/pictures/red.gif"); 123 String red = redFile.getAbsoluteFile().getCanonicalPath(); 124 125 File blueFile = new File ("./test/pictures/blue.gif"); 128 String blue = "file:///" + blueFile.getAbsoluteFile().getCanonicalPath(); 129 blue = blue.replace('\\','/'); 130 131 String commonPath = new File ("./test/HtmlTest.html").getParent(); 138 139 generator.setResourceInExampleHtml("GREEN", green); 140 generator.setResourceInExampleHtml("RED", red); 141 generator.setResourceInExampleHtml("BLUE", blue); 142 143 InputStream [] in = {generator.getGifImage()}; 145 146 see = new SignedAndEnvelopedSMIME(smtpHost, from, subject, "ISO-8859-1"); 148 149 see.setContent( generator.getHtmlString(), "text/html", commonPath, in ); 151 155 see.addAttachment(generator.getZipStream(), "test.zip"); 159 160 File attachment2 = new File ("./test/AdobeAcrobatTest.pdf"); 162 see.addAttachment(attachment2); 163 File attachment3 = new File ("./test/Word2000Test.doc"); 164 see.addAttachment(attachment3); 165 166 if (fileName!=null) { 167 see.addAttachment(fileName); } 169 170 see.setReply(from); 172 see.addRecipient(addressTO, "TO", cerFileName); 176 see.setCapabilities("SYMMETRIC", 5, 3, 1, 4, 2); see.setCapabilities("ENCIPHER", 1, 0, 0, 0, 0); see.setCapabilities("SIGNATURE", 3, 2, 1, 4, 0); 180 see.addSigner(pfxfileName, password, digestAlgorithm, includingCert, includingSignAttrib); 181 182 if (algorithmName.equals("RC240")) 183 { 184 System.out.println("Creating signed and encrypted message with RC2 - 40 bits algorithm... "); 185 see.signingAndEnveloping("SIGN_FIRST"); } 188 else if (algorithmName.equals("RC264")) 189 { 190 System.out.println("Creating signed and encrypted message with RC2 - 64 bits algorithm... "); 191 see.signingAndEnveloping(see.RC2_CBC, 64, "SIGN_FIRST"); } 193 else if (algorithmName.equals("RC2128")) 194 { 195 System.out.println("Creating signed and encrypted message with RC2 - 128 bits algorithm... "); 196 see.signingAndEnveloping(see.RC2_CBC, 128, "SIGN_FIRST"); } 198 else if (algorithmName.equals("DES")) 199 { 200 System.out.println("Creating signed and encrypted message with DES algorithm... "); 201 see.signingAndEnveloping(see.DES, 56, "SIGN_FIRST"); } 203 else if (algorithmName.equals("3DES")) 204 { 205 System.out.println("Creating signed and encrypted message with 3DES algorithm... "); 206 see.signingAndEnveloping(see.DES_EDE3_CBC, 192, "SIGN_FIRST"); } 208 209 System.out.print("Sending signed and encrypted message ... "); 210 see.send(); System.out.println("done."); 213 214 } 215 catch (Exception e) { 216 SMIMEException.setErrorFilePath("Log"); if(e instanceof SMIMEException) { 218 SMIMEException eTmp = (SMIMEException)e; 219 eTmp.displayErrors(null); 221 e = eTmp.getNonSMIMEException(); 222 if(e != null) 223 e.printStackTrace(); 224 } 225 else { 226 e.printStackTrace(); 227 } 228 } 229 } 230 } | Popular Tags |