132 |
{ |
{ |
133 |
Provider[] p = Security.getProviders(); |
Provider[] p = Security.getProviders(); |
134 |
for (int i = 0; i < p.length; i++) |
for (int i = 0; i < p.length; i++) |
135 |
{ |
try |
136 |
String classname = p[i].getProperty("AlgorithmParameters." + algorithm); |
{ |
137 |
if (classname != null) |
return getInstance(algorithm, p[i]); |
138 |
return getInstance(classname, algorithm, p[i]); |
} |
139 |
} |
catch (NoSuchAlgorithmException ignored) {} |
140 |
|
|
141 |
throw new NoSuchAlgorithmException(algorithm); |
throw new NoSuchAlgorithmException(algorithm); |
142 |
} |
} |
167 |
if (p == null) |
if (p == null) |
168 |
throw new NoSuchProviderException(); |
throw new NoSuchProviderException(); |
169 |
|
|
170 |
return getInstance( |
return getInstance(algorithm, p); |
171 |
p.getProperty("AlgorithmParameters." + algorithm), algorithm, p); |
} |
172 |
|
|
173 |
|
/** |
174 |
|
* Generates an <code>AlgorithmParameterGenerator</code> object for the |
175 |
|
* requested algorithm, as supplied from the specified provider, if such a |
176 |
|
* parameter generator is available from the provider. Note: the |
177 |
|
* <code>provider</code> doesn't have to be registered. |
178 |
|
* |
179 |
|
* @param algorithm the string name of the algorithm. |
180 |
|
* @param provider the provider. |
181 |
|
* @return the new <code>AlgorithmParameterGenerator</code> object. |
182 |
|
* @throws NoSuchAlgorithmException if the <code>algorithm</code> is not |
183 |
|
* available from the <code>provider</code>. |
184 |
|
* @throws IllegalArgumentException if the <code>provider</code> is |
185 |
|
* <code>null</code>. |
186 |
|
* @since 1.4 |
187 |
|
*/ |
188 |
|
public static AlgorithmParameters getInstance(String algorithm, |
189 |
|
Provider provider) |
190 |
|
throws NoSuchAlgorithmException |
191 |
|
{ |
192 |
|
if (provider == null) |
193 |
|
throw new IllegalArgumentException(); |
194 |
|
|
195 |
|
// try the name as is |
196 |
|
String className = provider.getProperty("AlgorithmParameters." + algorithm); |
197 |
|
if (className == null) // try all uppercase |
198 |
|
{ |
199 |
|
String upper = algorithm.toUpperCase(); |
200 |
|
className = provider.getProperty("AlgorithmParameters." + upper); |
201 |
|
if (className == null) // try if it's an alias |
202 |
|
{ |
203 |
|
String alias = |
204 |
|
provider.getProperty("Alg.Alias.AlgorithmParameters." + algorithm); |
205 |
|
if (alias == null) // try all-uppercase alias name |
206 |
|
{ |
207 |
|
alias = provider.getProperty("Alg.Alias.AlgorithmParameters." + upper); |
208 |
|
if (alias == null) // spit the dummy |
209 |
|
throw new NoSuchAlgorithmException(algorithm); |
210 |
|
} |
211 |
|
className = provider.getProperty("AlgorithmParameters." + alias); |
212 |
|
if (className == null) |
213 |
|
throw new NoSuchAlgorithmException(algorithm); |
214 |
|
} |
215 |
|
} |
216 |
|
return getInstance(className, algorithm, provider); |
217 |
} |
} |
218 |
|
|
219 |
private static AlgorithmParameters getInstance(String classname, |
private static AlgorithmParameters getInstance(String classname, |