com.monarchapis.common.util.HmacUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-client Show documentation
Show all versions of rest-client Show documentation
A Fluent API wrapper around Apache HTTP Client that handles both synchronous and asynchronous REST calls.
The newest version!
/*
* Copyright (C) 2015 CapTech Ventures, Inc.
* (http://www.captechconsulting.com) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.monarchapis.common.util;
import java.util.HashMap;
import java.util.Map;
import com.monarchapis.common.exception.ClientException;
/**
* Utility class used to translate simple MHac algorithm names to the Java
* algorithm names.
*
* @author Phil Kedy
*/
public final class HmacUtils {
/**
* The algorithm lookup map
*/
private static Map algorithmLookup = new HashMap();
static {
algorithmLookup.put("md5", "HmacMD5");
algorithmLookup.put("sha1", "HmacSHA1");
algorithmLookup.put("sha256", "HmacSHA256");
}
private HmacUtils() {
}
/**
* Performs the algorithm name lookup.
*
* @param algorithm
* The simple algorithm name
* @return the Java algorithm name.
*/
public static String getHMacAlgorithm(String algorithm) {
String digestAlgorithm = algorithmLookup.get(algorithm);
if (digestAlgorithm == null) {
throw new ClientException("Invalid algorithm " + algorithm);
}
return digestAlgorithm;
}
}