common.crypto.HMAC Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unbound-java-provider Show documentation
Show all versions of unbound-java-provider Show documentation
This is a collection of JAVA libraries that implement Unbound cryptographic classes for JAVA provider, PKCS11 wrapper, cryptoki, and advapi
package com.unbound.common.crypto;
import com.unbound.common.STR;
import javax.crypto.Mac;
public class HMAC
{
private Mac mac;
protected HMAC(String type, byte[] key)
{
mac = SystemProvider.Mac.getInstance(type);
}
public byte[] end()
{
return mac.doFinal();
}
public HMAC update(byte[] in)
{
mac.update(in);
return this;
}
public HMAC update(String in)
{
mac.update(STR.utf8(in));
return this;
}
public static final class SHA256 extends HMAC
{
public SHA256(byte[] key)
{
super("HmacSHA256", key);
}
public static byte[] hmac(byte[] key, byte[] in)
{
return new SHA256(key).update(in).end();
}
public static byte[] hmac(byte[] key, String in)
{
return new SHA256(key).update(in).end();
}
}
public static final class SHA512 extends HMAC
{
public SHA512(byte[] key)
{
super("HmacSHA512", key);
}
public static byte[] hmac(byte[] key, byte[] in)
{
return new SHA512(key).update(in).end();
}
public static byte[] hmac(byte[] key, String in)
{
return new SHA512(key).update(in).end();
}
}
}