authentication – Generating HMAC using Java

Just wanted to ask if this is the write way to generate an HMAC using Java, and if it is not, then what is the right way?

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.HmacAlgorithms;
import org.apache.commons.codec.digest.HmacUtils;

import java.nio.charset.StandardCharsets;

public class HMACGenerator {

    public static final String API_SECRET_CODE = "The quick brown fox jumps over the lazy dog";
    public static String generateHMAC(String key, String message) {
        var keyBytes = key.getBytes(StandardCharsets.UTF_8);
        final var hmacHelper = HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_SHA_512, keyBytes);
        final Hex hexHelper = new Hex();
        final var raw = hmacHelper.doFinal(message.getBytes(StandardCharsets.UTF_8));
        final var hex = hexHelper.encode(raw);
        return Base64.encodeBase64String(hex);

Thanks in advance.