Source Code Cross Referenced for KeyStoreGenerator.java in  » Net » JGroups-2.4.1-sp3 » org » jgroups » demos » 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 » Net » JGroups 2.4.1 sp3 » org.jgroups.demos 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //$Id: KeyStoreGenerator.java,v 1.2 2005/01/07 15:15:26 steview Exp $
002:
003:        package org.jgroups.demos;
004:
005:        import java.io.FileOutputStream;
006:        import java.io.OutputStream;
007:        import java.security.KeyStore;
008:
009:        import javax.crypto.KeyGenerator;
010:        import javax.crypto.SecretKey;
011:
012:        /**
013:         * Generates a keystore file that has a SecretKey in it. It is not possible to 
014:         * use the keytool JDk tool to achieve this. This is a simple way to generate 
015:         * a JCEKS format keystore and SecretKey.
016:         * 
017:         * Usage is --alg ALGNAME --size ALGSIZE --storeName FILENAME --storePass PASSWORD --alias KEYALIAS
018:         * 
019:         * Any of args are optional and will default to
020:         * <ul>
021:         * <li>ALGNAME = Blowfish 
022:         * <li>ALGSIZE = 56
023:         * <li>FILENAME = defaultStore.keystore
024:         * <li>PASSWORD = changeit
025:         * <li>ALIAS = mykey
026:         * </ul>
027:         * 
028:         * @author S Woodcock
029:         *
030:         */
031:        public class KeyStoreGenerator {
032:
033:            static String symAlg = "Blowfish";
034:            static int keySize = 56;
035:            static String keyStoreName = "defaultStore.keystore";
036:            static String storePass = "changeit";
037:            static String alias = "myKey";
038:
039:            public static void main(String[] args) {
040:
041:                int i = 0, j;
042:                String arg = null;
043:                ;
044:                boolean specified = false;
045:
046:                while (i < args.length && args[i].startsWith("-")) {
047:                    arg = args[i++];
048:                    System.out.println("Found arg of " + arg);
049:                    if (arg.equalsIgnoreCase("--alg")) {
050:                        if (i < args.length) {
051:                            symAlg = args[i++];
052:                        } else {
053:                            System.out
054:                                    .println("No Algorithm supplied using default of "
055:                                            + symAlg);
056:                        }
057:                    } else if (arg.equalsIgnoreCase("--size")) {
058:                        if (i < args.length) {
059:                            keySize = Integer.parseInt(args[i++]);
060:                        } else {
061:                            System.out
062:                                    .println("No Size supplied using default of "
063:                                            + keySize);
064:                        }
065:                    } else if (arg.equalsIgnoreCase("--storeName")) {
066:
067:                        if (i < args.length) {
068:                            String temp = args[i++];
069:                            keyStoreName = temp;
070:                        } else {
071:                            System.out
072:                                    .println("No keystore supplied using default of "
073:                                            + keyStoreName);
074:                        }
075:                    } else if (arg.equalsIgnoreCase("--storePass")) {
076:                        if (i < args.length) {
077:                            storePass = args[i++];
078:                        } else {
079:                            System.out
080:                                    .println("No password supplied using default of "
081:                                            + storePass);
082:                        }
083:                    } else if (arg.equalsIgnoreCase("--alias")) {
084:                        if (i < args.length) {
085:                            alias = args[i++];
086:                        } else {
087:                            System.out
088:                                    .println("No alias supplied using default of "
089:                                            + alias);
090:                        }
091:                    }
092:                }
093:                System.out.println("Creating file '" + keyStoreName
094:                        + "' using Algorithm '" + symAlg + "' size '" + keySize
095:                        + "'");
096:
097:                OutputStream stream = null;
098:                try {
099:                    stream = new FileOutputStream(keyStoreName);
100:                    SecretKey key = initSymKey();
101:                    KeyStore store = KeyStore.getInstance("JCEKS");
102:                    store.load(null, null);
103:                    store
104:                            .setKeyEntry(alias, key, storePass.toCharArray(),
105:                                    null);
106:                    store.store(stream, storePass.toCharArray());
107:
108:                } catch (Exception e) {
109:                    e.printStackTrace();
110:                } finally {
111:                    try {
112:                        stream.close();
113:                    } catch (Exception e) {
114:
115:                    }
116:                }
117:                System.out.println("Finished keystore creation");
118:            }
119:
120:            public static SecretKey initSymKey() throws Exception {
121:                KeyGenerator keyGen = null;
122:                // generate secret key
123:
124:                keyGen = KeyGenerator.getInstance(getAlgorithm(symAlg));
125:
126:                keyGen.init(keySize);
127:                SecretKey secretKey = keyGen.generateKey();
128:
129:                return secretKey;
130:
131:            }
132:
133:            private static String getAlgorithm(String s) {
134:                int index = s.indexOf("/");
135:                if (index == -1)
136:                    return s;
137:
138:                return s.substring(0, index);
139:            }
140:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.