/Users/lyon/j4p/src/security/SignUtils.java

1    package security; 
2     
3    import classUtils.pack.DependencyUtils; 
4    import sun.security.tools.JarSigner; 
5     
6    /** 
7     * DocJava, Inc. User: lyon Date: May 26, 2004 
8     * Time: 7:40:22 AM 
9     */ 
10   public class SignUtils { 
11          public static void main(String[] args) { 
12           jarIt(); 
13    
14       } 
15       public static void testPackSignAndVerify() { 
16           String className = "dhry.Main"; 
17    
18           String keystoreName = "keystore"; 
19           String storepass = "password"; 
20           String alias = "docjava"; 
21    
22           packSignAndVerify(className, 
23                             keystoreName, 
24                             storepass, 
25                             alias); 
26       } 
27       public static void packSignAndVerify() { 
28           packSignAndVerify( 
29                   gui.In.getString("enter class name"), 
30                   futils.Futil.getReadFile("select keystore")+"", 
31                   gui.In.getString("enter password"), 
32                   gui.In.getString("enter alias") 
33           ); 
34    
35       } 
36    
37    
38       public static void packSignAndVerify( 
39               String className, 
40               String keystoreName, 
41               String storepass, 
42               String alias) { 
43           String jarFileName = className + ".jar"; 
44           DependencyUtils.pack(className, 
45                         jarFileName); 
46           sign(keystoreName, 
47                storepass, 
48                jarFileName, 
49                alias); 
50    
51           verify(jarFileName); 
52       } 
53        public static void jarIt() { 
54            String a[] = { 
55                "-help" 
56            }; 
57           sun.tools.jar.Main.main(a); 
58       } 
59       public static void sign(String keystoreName, 
60                               String storepass, 
61                               String jarFileName, 
62                               String alias) { 
63           JarSigner js = new JarSigner(); 
64    
65           String a[] = { 
66               "-keystore", 
67               keystoreName, 
68               "-storepass", 
69               storepass, 
70               jarFileName, 
71               alias 
72    
73           }; 
74           js.run(a); 
75       } 
76       /** 
77        * This method causes the callers thread of 
78        * execution to terminate after the run! 
79        * @param jarFileName 
80        */ 
81       public static void verify(String jarFileName) { 
82           JarSigner js = new JarSigner(); 
83           System.out.println("verifying:"+jarFileName); 
84           String a[] = { 
85               "-verify", 
86               "-verbose", 
87               jarFileName, 
88    
89           }; 
90           js.run(a); 
91       } 
92   } 
93