Class HMAC


  • @ThreadSafe
    public class HMAC
    extends Object
    Static methods for Hash-based Message Authentication Codes (HMAC). This class is thread-safe.
    Version:
    2015-04-23
    Author:
    Axel Nennker, Vladimir Dzhuvinov
    • Constructor Detail

      • HMAC

        public HMAC()
    • Method Detail

      • compute

        public static byte[] compute​(String alg,
                                     byte[] secret,
                                     byte[] message,
                                     Provider provider)
                              throws JOSEException
        Computes a Hash-based Message Authentication Code (HMAC) for the specified secret and message.
        Parameters:
        alg - The Java Cryptography Architecture (JCA) HMAC algorithm name. Must not be null.
        secret - The secret. Must not be null.
        message - The message. Must not be null.
        provider - The JCA provider, or null to use the default one.
        Returns:
        A MAC service instance.
        Throws:
        JOSEException - If the algorithm is not supported or the MAC secret key is invalid.
      • compute

        public static byte[] compute​(SecretKey secretKey,
                                     byte[] message,
                                     Provider provider)
                              throws JOSEException
        Computes a Hash-based Message Authentication Code (HMAC) for the specified secret key and message.
        Parameters:
        secretKey - The secret key, with the appropriate HMAC algorithm. Must not be null.
        message - The message. Must not be null.
        provider - The JCA provider, or null to use the default one.
        Returns:
        A MAC service instance.
        Throws:
        JOSEException - If the algorithm is not supported or the MAC secret key is invalid.