com.aliyun.auth.signature.signer.SignAlgorithmHmacSHA256 Maven / Gradle / Ivy
The newest version!
package com.aliyun.auth.signature.signer;
import com.aliyun.auth.signature.exception.SignatureException;
import javax.crypto.Mac;
import java.security.NoSuchAlgorithmException;
public enum SignAlgorithmHmacSHA256 {
HmacSHA256("HmacSHA256");
private final ThreadLocal reference;
private final String algorithmName;
SignAlgorithmHmacSHA256(String algorithmName) {
this.algorithmName = algorithmName;
reference = new MacThreadLocal(algorithmName);
}
public String getAlgorithmName() {
return this.algorithmName;
}
public Mac getMac() {
return reference.get();
}
private static class MacThreadLocal extends ThreadLocal {
private final String algorithmName;
MacThreadLocal(String algorithmName) {
this.algorithmName = algorithmName;
}
@Override
protected Mac initialValue() {
try {
return Mac.getInstance(algorithmName);
} catch (NoSuchAlgorithmException e) {
throw new SignatureException("Unable to fetch Mac instance for Algorithm "
+ algorithmName + e.getMessage());
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy