1 7 8 package org.enhydra.oyster.test; 9 10 import javax.mail.Transport ; 11 import org.enhydra.oyster.smime.EnvelopedSMIME; 12 import org.enhydra.oyster.exception.SMIMEException; 13 14 30 public class TestEncrypt 31 { 32 33 public static void main (String [] args) 34 { 35 36 String subject = "S/MIME encrypted message - Subject test: ÜüÄäÖöÜüß"; 37 String content = "S/MIME encrypted message example\r\nContent test: ÜüÄäÖöÜüß!"; 38 String from = "sender@together.at"; 39 40 if (args.length < 4) 41 { 42 System.err.println( 43 System.getProperty("line.separator") + 44 "Usage of TestEncrypt: " + 45 System.getProperty("line.separator") + 46 "java TestEncrypt <mailHost> <mailAddress> <cerFileName> " + 47 "<algorithmName> [<attachment>]" + 48 System.getProperty("line.separator") + 49 System.getProperty("line.separator") + 50 "Examples:" + 51 System.getProperty("line.separator") + 52 "java TestEncrypt together.at recipient@together.at " + 53 "recipient512.cer RC240 " + 54 System.getProperty("line.separator") + 55 "java TestEncrypt together.at recipient@together.at " + 56 "recipient512.cer DES .\\test\\Zip8Test.zip"); 57 System.exit(-1); 58 } 59 String smtpHost = args[0]; 60 String addressTO = args[1]; 61 String cerFileName = args[2]; 62 String algorithmName = args[3]; 63 String fileName = null; 64 if (args.length > 4) 65 fileName = args[4]; 66 67 String addressCC = "recipient@together.at"; 68 String addressBCC = "recipient@together.at"; 69 70 subject = algorithmName + " " + cerFileName + " " + subject; 71 72 EnvelopedSMIME es = null; 73 74 try 75 { 76 es = new EnvelopedSMIME(smtpHost, from, subject, content, "ISO-8859-1"); 78 79 if (fileName!=null) { 80 es.addAttachment(fileName); } 82 83 es.setReply(from); 85 es.addRecipient(addressTO, "TO", cerFileName); 89 if (algorithmName.equals("RC240")) 90 { 91 System.out.println("Creating the encrypted message with RC2_CBC - 40 bits algorithm... "); 92 es.enveloping(); } 95 else if (algorithmName.equals("RC264")) 96 { 97 System.out.println("Creating the encrypted message with RC2_CBC - 64 bits algorithm... "); 98 es.enveloping(es.RC2_CBC, 64); } 100 else if (algorithmName.equals("RC2128")) 101 { 102 System.out.println("Creating the encrypted message with RC2_CBC - 128 bits algorithm... "); 103 es.enveloping(es.RC2_CBC, 128); } 105 else if (algorithmName.equals("DES")) 106 { 107 System.out.println("Creating the encrypted message with DES algorithm... "); 108 es.enveloping(es.DES, 56); } 110 else if (algorithmName.equals("3DES")) 111 { 112 System.out.println("Creating the encrypted message with DES_EDE3_CBC algorithm... "); 113 es.enveloping(es.DES_EDE3_CBC, 192); } 115 System.out.print("Sending encrypted message ... "); 116 es.send(); System.out.println("done."); 119 120 } 121 catch (Exception e) { 122 SMIMEException.setErrorFilePath("Log"); if(e instanceof SMIMEException) { 124 SMIMEException eTmp = (SMIMEException)e; 125 eTmp.displayErrors(null); 127 e = eTmp.getNonSMIMEException(); 128 if(e != null) 129 e.printStackTrace(); 130 } 131 else { 132 e.printStackTrace(); 133 } 134 } 135 } 136 137 } 138 139 140 141 | Popular Tags |