1 package org.jacorb.security.ssl.sun_jsse; 2 3 22 23 24 import java.security.*; 25 import java.security.cert.*; 26 import java.io.*; 27 28 34 35 public class KeyStoreUtil 36 { 37 42 43 public static KeyStore getKeyStore( String file_name, 44 char[] storepass ) 45 throws IOException, java.security.GeneralSecurityException 46 { 47 InputStream in = null; 48 49 java.net.URL url = 50 Thread.currentThread().getContextClassLoader().getResource(file_name); 51 if (url != null) 52 { 53 in = url.openStream(); 54 } 55 else 56 { 57 File f = new File( file_name ); 59 if( ! f.exists() ) 60 { 61 String name = 63 System.getProperty( "user.home" ) + 64 System.getProperty( "file.separator" ) + 65 file_name; 66 67 f = new File( name ); 68 69 if(f.exists()) 70 { 71 in = new FileInputStream( f ); 72 } 73 } 74 else 75 { 76 in = new FileInputStream( f ); 77 } 78 } 79 80 if (in == null) 81 { 82 throw new IOException("Unable to find keystore file " + 83 file_name); 84 } 85 86 KeyStore ks = KeyStore.getInstance( "JKS" ); 87 ks.load( in, storepass ); 88 in.close(); 89 return ks; 90 } 91 } 92 | Popular Tags |