Source Code Cross Referenced for TestEncSigKeyStore.java in  » Web-Mail » oyster » org » enhydra » oyster » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Mail » oyster » org.enhydra.oyster.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Title:        Oyster Project
003:         * Description:  S/MIME email sending capabilities
004:         * @Author       Vladimir Radisic
005:         * @Version      2.1.6
006:         */
007:
008:        package org.enhydra.oyster.test;
009:
010:        import org.enhydra.oyster.cms.consts.CapabilitiesConstants;
011:        import javax.mail.Transport;
012:        import org.enhydra.oyster.smime.SignedAndEnvelopedSMIME;
013:        import org.enhydra.oyster.exception.SMIMEException;
014:
015:        /**
016:         * Tests enveloping and signing process. Enveloped and signed text/plain message
017:         * with or withouth attachments can be sent by this test. This example is test
018:         * for enveloping and signing of email message by usage of keys and certificates
019:         * from optional KeyStore storage file. To get help for this example type:
020:         * "java org.enhydra.oyster.test.TestEncSigKeyStore" in command line. It is
021:         * assumed that oyster_tests.jar is in your classpath.<BR>
022:         * <BR>
023:         * Parameters passed to example are:<BR>
024:         * &lt;mailHost&gt; &lt;mailAddress&gt; &lt;cerFileName&gt; &lt;algorithmName&gt;
025:         * &lt;digestAlgorithm&gt; &lt;includingCert&gt; &lt;includingSignAttrib&gt;
026:         * &lt;pfxFileName&gt; [&lt;attachment&gt;] <BR>
027:         * <BR>
028:         * &lt;digestAlgorithm&gt; could be: SHA1_WITH_RSA, MD2_WITH_RSA, MD5_WITH_RSA or SHA1_WITH_DSA.<BR>
029:         * &lt;includingCert&gt; could be: true/false<BR>
030:         * &lt;includingSignAttrib&gt; could be: true/false<BR>
031:         * &lt;algorithmName&gt; could be: RC240, RC264, RC2128, 3DES or 3DES<BR>
032:         * <BR>
033:         * Note that password for KeyStore file ('keystore.ks') used in this example,
034:         * is "together", and the KeyStore has type 'BKS'. You may change this values in
035:         * source code of TestSignedKeyStore.java in order to use them with other
036:         * KeyStore files. Also, email address "FROM" is fixed to: "sender@together.at",
037:         * and should change too, in order to use them with other KeyStore file entryes.
038:         * Aliases which exist in keystore.ks for corresponding private keys and
039:         * certificate chains are: 'senderDSA512.pfx', 'recipient1024.pfx',
040:         * 'recipient2048.pfx', 'recipient512.pfx', 'recipientDSA1024.pfx',
041:         * 'recipientDSA512.pfx', 'sender1024.pfx', 'sender2048.pfx', 'sender512.pfx',
042:         * 'senderDSA1024.pfx'.
043:         */
044:        public class TestEncSigKeyStore {
045:
046:            public static void main(String[] args) {
047:
048:                String subject = "S/MIME enveloped and signed message - Subject test: ÜüÄäÖöÜüß";
049:                String content = "S/MIME enveloped and signed message example\r\nContent test: ÜüÄäÖöÜüß!";
050:                String from = "sender@together.at";
051:                String password = "together";
052:                String keyStoreFile = "keystore.ks";
053:
054:                if (args.length < 8) {
055:                    System.err
056:                            .println(System.getProperty("line.separator")
057:                                    + "Usage of TestEncSigKeyStore: "
058:                                    + System.getProperty("line.separator")
059:                                    + "java TestEncSig <mailHost> <mailAddress> <cerKeyStoreAlias> "
060:                                    + "<algorithmName> <digestAlgorithm> <includingCert> <includingSignAttrib> "
061:                                    + "<pfxKeyStoreAlias> [<attachment>]"
062:                                    + System.getProperty("line.separator")
063:                                    + System.getProperty("line.separator")
064:                                    + "Examples:"
065:                                    + System.getProperty("line.separator")
066:                                    + "java TestEncSigKeyStore together.at recipient@together.at recipient512.cer "
067:                                    + "RC240 SHA1_WITH_RSA true true sender512.pfx"
068:                                    + System.getProperty("line.separator")
069:                                    + "java TestEncSigKeyStore together.at recipient@together.at recipient512.cer "
070:                                    + "DES MD5_WITH_RSA true true sender512.pfx .\\test\\Zip8Test.zip");
071:
072:                    System.exit(-1);
073:                }
074:
075:                String smtpHost = args[0];
076:                String addressTO = args[1];
077:                String cerFileName = args[2];
078:                String algorithmName = args[3];
079:                String digestAlgorithm = args[4];
080:
081:                boolean includingCert = true;
082:                if (args[5].equals("true"))
083:                    includingCert = true;
084:                else
085:                    includingCert = false;
086:
087:                boolean includingSignAttrib = true;
088:                if (args[6].equals("true"))
089:                    includingSignAttrib = true;
090:                else
091:                    includingSignAttrib = false;
092:
093:                String pfxfileName = args[7];
094:
095:                String fileName = null;
096:                if (args.length > 8)
097:                    fileName = args[8];
098:
099:                String addressCC = "recipient@together.at";
100:                String addressBCC = "recipient@together.at";
101:
102:                subject = args[2] + " " + args[3] + " " + args[4] + " "
103:                        + args[5] + " " + args[6] + " " + args[7] + " "
104:                        + subject;
105:
106:                SignedAndEnvelopedSMIME ess = null;
107:
108:                try {
109:                    // Construction of enveloped and signed smime object
110:                    ess = new SignedAndEnvelopedSMIME(smtpHost, from, subject,
111:                            content, "ISO-8859-1");
112:
113:                    if (fileName != null) {
114:                        ess.addAttachment(fileName); // optional - use this if send attachment
115:                    }
116:
117:                    ess.setReply(from); // optional
118:
119:                    String alias = cerFileName.replaceAll(".cer", ".pfx"); // switch name to appropriate alias
120:                    ess.addRecipient(addressTO, "TO", keyStoreFile, ess.BKS,
121:                            password, alias); // mandatory
122:                    //      ess.addRecipient(addressTO, "CC", keyStoreFile, ess.BKS, password, cerFileName); // optional
123:                    //      ess.addRecipient(addressTO, "BCC", keyStoreFile, ess.BKS, password, cerFileName); // optional
124:
125:                    ess.setCapabilities(CapabilitiesConstants.SYMMETRIC,
126:                            new String[] { CapabilitiesConstants.DES_EDE3_CBC,
127:                                    CapabilitiesConstants.RC2_CBC_128,
128:                                    CapabilitiesConstants.RC2_CBC_40,
129:                                    CapabilitiesConstants.DES,
130:                                    CapabilitiesConstants.RC2_CBC_64 }); // optional
131:                    ess.setCapabilities(CapabilitiesConstants.ENCIPHER,
132:                            new String[] { CapabilitiesConstants.RSA }); // optional
133:                    ess.setCapabilities(CapabilitiesConstants.SIGNATURE,
134:                            new String[] { CapabilitiesConstants.SHA1_WITH_RSA,
135:                                    CapabilitiesConstants.MD5_WITH_RSA,
136:                                    CapabilitiesConstants.MD2_WITH_RSA,
137:                                    CapabilitiesConstants.SHA1_WITH_DSA }); // optional
138:                    //      see.setCapabilities("SYMMETRIC", 5, 3, 1, 4, 2);  // optional
139:                    //      see.setCapabilities("ENCIPHER", 1, 0, 0, 0, 0);  // optional
140:                    //      see.setCapabilities("SIGNATURE", 3, 2, 1, 4, 0);  // optional
141:
142:                    alias = pfxfileName; // switch name to appropriate alias
143:                    ess
144:                            .addSigner(keyStoreFile, ess.BKS, password, alias,
145:                                    digestAlgorithm, includingCert,
146:                                    includingSignAttrib); // mandatory
147:
148:                    if (algorithmName.equals("RC240")) {
149:                        System.out
150:                                .println("Creating enveloped and signed message with RC2 - 40 bits algorithm... ");
151:                        ess.signingAndEnveloping("ENCRYPT_FIRST"); // instead of this next line could be used
152:                        //        ess.enveloping(ess.RC2_CBC, 40, "ENCRYPT_FIRST");
153:                    } else if (algorithmName.equals("RC264")) {
154:                        System.out
155:                                .println("Creating enveloped and signed message with RC2 - 64 bits algorithm... ");
156:                        ess.signingAndEnveloping(ess.RC2_CBC, 64,
157:                                "ENCRYPT_FIRST"); // send message with RC2 - 64 bits algorithm
158:                    } else if (algorithmName.equals("RC2128")) {
159:                        System.out
160:                                .println("Creating enveloped and signed message with RC2 - 128 bits algorithm... ");
161:                        ess.signingAndEnveloping(ess.RC2_CBC, 128,
162:                                "ENCRYPT_FIRST"); // send message with RC2 - 128 bits algorithm
163:                    } else if (algorithmName.equals("DES")) {
164:                        System.out
165:                                .println("Creating enveloped and signed message with DES algorithm... ");
166:                        ess.signingAndEnveloping(ess.DES, 56, "ENCRYPT_FIRST"); // send message with DES - 56 bits algorithm
167:                    } else if (algorithmName.equals("3DES")) {
168:                        System.out
169:                                .println("Creating enveloped and signed message with 3DES algorithm... ");
170:                        ess.signingAndEnveloping(ess.DES_EDE3_CBC, 192,
171:                                "ENCRYPT_FIRST"); // send message with 3DES - 192 bits algorithm
172:                    }
173:
174:                    System.out
175:                            .print("Sending enveloped and signed message ... ");
176:                    ess.send(); // instead of this next line could be used
177:                    //      Transport.send(ess.getSignedMessage());
178:                    System.out.println("done.");
179:
180:                } catch (Exception e) {
181:                    e.printStackTrace();
182:                }
183:            }
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.