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 14 36 public class TestSigEnc 37 { 38 39 public static void main(String [] args) 40 { 41 42 String subject = "S/MIME signed and enveloped message - Subject test: ÜüÄäÖöÜüß"; 43 String content = "S/MIME signed and enveloped message example\r\nContent test: ÜüÄäÖöÜüß!"; 44 String from = "sender@together.at"; 45 String password = "together"; 46 47 if (args.length < 8) 48 { 49 System.err.println( 50 System.getProperty("line.separator") + 51 "Usage of TestSigEnc: " + 52 System.getProperty("line.separator") + 53 "java TestSigned <mailHost> <mailAddress> <cerFileName> " + 54 "<algorithmName> <digestAlgorithm> <includingCert> <includingSignAttrib> " + 55 "<pfxFileName> [<attachment>]"+ 56 System.getProperty("line.separator") + 57 System.getProperty("line.separator") + 58 "Examples:" + 59 System.getProperty("line.separator") + 60 "java TestSigEnc together.at recipient@together.at recipient512.cer " + 61 "RC240 SHA1_WITH_RSA true true sender512.pfx" + 62 System.getProperty("line.separator") + 63 "java TestSigEnc together.at recipient@together.at recipient512.cer " + 64 "DES MD5_WITH_RSA true true sender512.pfx .\\test\\Zip8Test.zip"); 65 66 System.exit(-1); 67 } 68 69 String smtpHost = args[0]; 70 String addressTO = args[1]; 71 String cerFileName = args[2]; 72 String algorithmName = args[3]; 73 String digestAlgorithm = args[4]; 74 75 boolean includingCert = true; 76 if (args[5].equals("true")) 77 includingCert = true; 78 else 79 includingCert = false; 80 81 boolean includingSignAttrib = true; 82 if (args[6].equals("true")) 83 includingSignAttrib = true; 84 else 85 includingSignAttrib = false; 86 87 String pfxfileName = args[7]; 88 89 String fileName = null; 90 if (args.length > 8) 91 fileName = args[8]; 92 93 String addressCC = "recipient@together.at"; 94 String addressBCC = "recipient@together.at"; 95 96 subject = args[2] + " " + args[3] + " " + args[4] + " " + args[5] + " " + 97 args[6] + " " + args[7] + " " + subject; 98 99 SignedAndEnvelopedSMIME see = null; 100 101 try { 102 see = new SignedAndEnvelopedSMIME(smtpHost, from, subject, content, "ISO-8859-1"); 104 105 if (fileName!=null) { 106 see.addAttachment(fileName); } 108 109 see.setReply(from); 111 see.addRecipient(addressTO, "TO", cerFileName); 115 see.setCapabilities("SYMMETRIC", 5, 3, 1, 4, 2); see.setCapabilities("ENCIPHER", 1, 0, 0, 0, 0); see.setCapabilities("SIGNATURE", 3, 2, 1, 4, 0); 119 see.addSigner(pfxfileName, password, digestAlgorithm, includingCert, includingSignAttrib); 120 121 if (algorithmName.equals("RC240")) 122 { 123 System.out.println("Creating signed and encrypted message with RC2 - 40 bits algorithm... "); 124 see.signingAndEnveloping("SIGN_FIRST"); } 127 else if (algorithmName.equals("RC264")) 128 { 129 System.out.println("Creating signed and encrypted message with RC2 - 64 bits algorithm... "); 130 see.signingAndEnveloping(see.RC2_CBC, 64, "SIGN_FIRST"); } 132 else if (algorithmName.equals("RC2128")) 133 { 134 System.out.println("Creating signed and encrypted message with RC2 - 128 bits algorithm... "); 135 see.signingAndEnveloping(see.RC2_CBC, 128, "SIGN_FIRST"); } 137 else if (algorithmName.equals("DES")) 138 { 139 System.out.println("Creating signed and encrypted message with DES algorithm... "); 140 see.signingAndEnveloping(see.DES, 56, "SIGN_FIRST"); } 142 else if (algorithmName.equals("3DES")) 143 { 144 System.out.println("Creating signed and encrypted message with 3DES algorithm... "); 145 see.signingAndEnveloping(see.DES_EDE3_CBC, 192, "SIGN_FIRST"); } 147 148 System.out.print("Sending signed and encrypted message ... "); 149 see.send(); System.out.println("done."); 152 153 } 154 catch (Exception e) { 155 SMIMEException.setErrorFilePath("Log"); if(e instanceof SMIMEException) { 157 SMIMEException eTmp = (SMIMEException)e; 158 eTmp.displayErrors(null); 160 e = eTmp.getNonSMIMEException(); 161 if(e != null) 162 e.printStackTrace(); 163 } 164 else { 165 e.printStackTrace(); 166 } 167 } 168 } 169 } | Popular Tags |