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