Added a check for JCE providers that are not working.

This commit is contained in:
Ioannis Canellos 2011-11-18 17:18:52 +02:00
parent b2d6c6b19c
commit 10d617a4ca
1 changed files with 12 additions and 1 deletions

View File

@ -63,7 +63,18 @@ public class JCECrypto implements Crypto {
@Override
public Mac hmac(String algorithm, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException {
Mac mac = provider == null ? Mac.getInstance(algorithm) : Mac.getInstance(algorithm, provider);
Mac mac = null;
if(provider != null) {
try {
mac = Mac.getInstance(algorithm, provider);
} catch(Exception e) {
//Provider does not function.
//Do nothing and let it fallback to the default way.
}
}
if(mac == null) {
mac = Mac.getInstance(algorithm);
}
SecretKeySpec signingKey = new SecretKeySpec(key, algorithm);
mac.init(signingKey);
return mac;