165 |
return getInstance(algorithm, p); |
return getInstance(algorithm, p); |
166 |
} |
} |
167 |
|
|
168 |
private static MessageDigest getInstance(String algorithm, Provider p) |
/** |
169 |
|
* Generates a <code>MessageDigest</code> object implementing the specified |
170 |
|
* algorithm, as supplied from the specified provider, if such an algorithm |
171 |
|
* is available from the provider. Note: the provider doesn't have to be |
172 |
|
* registered. |
173 |
|
* |
174 |
|
* @param algorithm the name of the algorithm requested. See Appendix A in |
175 |
|
* the Java Cryptography Architecture API Specification & Reference for |
176 |
|
* information about standard algorithm names. |
177 |
|
* @param provider the provider. |
178 |
|
* @return a Message Digest object implementing the specified algorithm. |
179 |
|
* @throws NoSuchAlgorithmException if the <code>algorithm</code> is not |
180 |
|
* available in the package supplied by the requested <code>provider</code>. |
181 |
|
* @throws IllegalArgumentException if the <code>provider</code> is |
182 |
|
* <code>null</code>. |
183 |
|
* @since 1.4 |
184 |
|
* @see Provider |
185 |
|
*/ |
186 |
|
public static MessageDigest getInstance(String algorithm, Provider provider) |
187 |
throws NoSuchAlgorithmException |
throws NoSuchAlgorithmException |
188 |
{ |
{ |
189 |
|
if (provider == null) |
190 |
|
throw new IllegalArgumentException(); |
191 |
|
|
192 |
// try the name as is |
// try the name as is |
193 |
String className = p.getProperty("MessageDigest." + algorithm); |
String className = provider.getProperty("MessageDigest." + algorithm); |
194 |
if (className == null) // try all uppercase |
if (className == null) // try all uppercase |
195 |
{ |
{ |
196 |
String upper = algorithm.toUpperCase(); |
String upper = algorithm.toUpperCase(); |
197 |
className = p.getProperty("MessageDigest." + upper); |
className = provider.getProperty("MessageDigest." + upper); |
198 |
if (className == null) // try if it's an alias |
if (className == null) // try if it's an alias |
199 |
{ |
{ |
200 |
String alias = p.getProperty("Alg.Alias.MessageDigest." +algorithm); |
String alias = provider.getProperty( |
201 |
|
"Alg.Alias.MessageDigest." +algorithm); |
202 |
if (alias == null) // try all-uppercase alias name |
if (alias == null) // try all-uppercase alias name |
203 |
{ |
{ |
204 |
alias = p.getProperty("Alg.Alias.MessageDigest." +upper); |
alias = provider.getProperty("Alg.Alias.MessageDigest." +upper); |
205 |
if (alias == null) // spit the dummy |
if (alias == null) // spit the dummy |
206 |
throw new NoSuchAlgorithmException(algorithm); |
throw new NoSuchAlgorithmException(algorithm); |
207 |
} |
} |
208 |
className = p.getProperty("MessageDigest." + alias); |
className = provider.getProperty("MessageDigest." + alias); |
209 |
if (className == null) |
if (className == null) |
210 |
throw new NoSuchAlgorithmException(algorithm); |
throw new NoSuchAlgorithmException(algorithm); |
211 |
} |
} |
212 |
} |
} |
213 |
return getInstance(className, algorithm, p); |
return getInstance(className, algorithm, provider); |
214 |
} |
} |
215 |
|
|
216 |
private static MessageDigest getInstance(String classname, |
private static MessageDigest getInstance(String classname, |