1 |
/* KeyFactory.java --- Key Factory Class |
/* KeyFactory.java --- Key Factory Class |
2 |
Copyright (C) 1999, 2003, Free Software Foundation, Inc. |
Copyright (C) 1999, 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
83 |
*/ |
*/ |
84 |
public class KeyFactory |
public class KeyFactory |
85 |
{ |
{ |
86 |
|
/** The service name for key factories. */ |
87 |
|
private static final String KEY_FACTORY = "KeyFactory"; |
88 |
|
|
89 |
private KeyFactorySpi keyFacSpi; |
private KeyFactorySpi keyFacSpi; |
90 |
private Provider provider; |
private Provider provider; |
91 |
private String algorithm; |
private String algorithm; |
128 |
for (int i = 0; i < p.length; i++) |
for (int i = 0; i < p.length; i++) |
129 |
try |
try |
130 |
{ |
{ |
131 |
getInstance(algorithm, p[i]); |
return getInstance(algorithm, p[i]); |
132 |
} |
} |
133 |
catch (NoSuchAlgorithmException ignored) {} |
catch (NoSuchAlgorithmException ignored) {} |
134 |
|
|
153 |
public static KeyFactory getInstance(String algorithm, String provider) |
public static KeyFactory getInstance(String algorithm, String provider) |
154 |
throws NoSuchAlgorithmException, NoSuchProviderException |
throws NoSuchAlgorithmException, NoSuchProviderException |
155 |
{ |
{ |
156 |
|
if (provider == null || provider.length() == 0) |
157 |
|
throw new IllegalArgumentException("Illegal provider"); |
158 |
|
|
159 |
Provider p = Security.getProvider(provider); |
Provider p = Security.getProvider(provider); |
160 |
if (p == null) |
if (p == null) |
161 |
throw new NoSuchProviderException(); |
throw new NoSuchProviderException(); |
184 |
throws NoSuchAlgorithmException |
throws NoSuchAlgorithmException |
185 |
{ |
{ |
186 |
if (provider == null) |
if (provider == null) |
187 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException("Illegal provider"); |
188 |
|
|
|
// try the name as is |
|
|
String className = provider.getProperty("KeyFactory." + algorithm); |
|
|
if (className == null) // try all uppercase |
|
|
{ |
|
|
String upper = algorithm.toUpperCase(); |
|
|
className = provider.getProperty("KeyFactory." + upper); |
|
|
if (className == null) // try if it's an alias |
|
|
{ |
|
|
String alias = |
|
|
provider.getProperty("Alg.Alias.KeyFactory." + algorithm); |
|
|
if (alias == null) // try all-uppercase alias name |
|
|
{ |
|
|
alias = provider.getProperty("Alg.Alias.KeyFactory." + upper); |
|
|
if (alias == null) // spit the dummy |
|
|
throw new NoSuchAlgorithmException(algorithm); |
|
|
} |
|
|
className = provider.getProperty("KeyFactory." + alias); |
|
|
if (className == null) |
|
|
throw new NoSuchAlgorithmException(algorithm); |
|
|
} |
|
|
} |
|
|
return getInstance(className, algorithm, provider); |
|
|
} |
|
|
|
|
|
private static KeyFactory getInstance(String classname, String algorithm, |
|
|
Provider provider) |
|
|
throws NoSuchAlgorithmException |
|
|
{ |
|
189 |
try |
try |
190 |
{ |
{ |
191 |
return new KeyFactory( |
return new KeyFactory((KeyFactorySpi) |
192 |
(KeyFactorySpi) Class.forName(classname).newInstance(), |
Engine.getInstance(KEY_FACTORY, algorithm, provider), |
193 |
provider, |
provider, algorithm); |
|
algorithm); |
|
|
} |
|
|
catch (ClassNotFoundException cnfe) |
|
|
{ |
|
|
throw new NoSuchAlgorithmException("Class not found"); |
|
194 |
} |
} |
195 |
catch (InstantiationException ie) |
catch (ClassCastException cce) |
196 |
{ |
{ |
197 |
throw new NoSuchAlgorithmException("Class instantiation failed"); |
throw new NoSuchAlgorithmException(algorithm); |
198 |
} |
} |
|
catch (IllegalAccessException iae) |
|
|
{ |
|
|
throw new NoSuchAlgorithmException("Illegal Access"); |
|
|
} |
|
199 |
} |
} |
200 |
|
|
201 |
/** |
/** |