Class MacCrypto

java.lang.Object
com.helixframework.crypto.mac.MacCrypto

public class MacCrypto extends Object
Verifies a MAC.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    compute(byte[] data)
    Computes the message authentication code (MAC) for the given data.
    byte[]
    Computes the message authentication code (MAC) for the given data.
    byte[]
    compute(String data, Charset charset)
    Computes the message authentication code (MAC) for the given data using the specified charset.
    computeAsBase64(byte[] data)
    Computes the message authentication code (MAC) for the given data and returns it as a Base64 encoded string.
    Computes the message authentication code (MAC) for the given data and returns it as a Base64 encoded string.
    computeAsBase64(String data, Charset charset)
    Computes the message authentication code (MAC) for the given data and returns it as a Base64 encoded string.
    void
    verify(byte[] mac, byte[] data)
    Verifies whether mac is a correct authentication code (MAC) for data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • compute

      public byte[] compute(byte[] data) throws GeneralSecurityException
      Computes the message authentication code (MAC) for the given data.
      Parameters:
      data - the data to compute the MAC for
      Returns:
      the computed MAC as a byte array
      Throws:
      GeneralSecurityException - if an error occurs during MAC computation
    • compute

      public byte[] compute(String data) throws GeneralSecurityException
      Computes the message authentication code (MAC) for the given data.
      Parameters:
      data - the data to compute the MAC for
      Returns:
      the computed MAC as a byte array
      Throws:
      GeneralSecurityException - if an error occurs during MAC computation
    • compute

      public byte[] compute(String data, Charset charset) throws GeneralSecurityException
      Computes the message authentication code (MAC) for the given data using the specified charset.
      Parameters:
      data - the data to compute the MAC for
      charset - the charset used to encode the data as bytes
      Returns:
      the computed MAC as a byte array
      Throws:
      GeneralSecurityException - if an error occurs during MAC computation
    • computeAsBase64

      public String computeAsBase64(byte[] data) throws GeneralSecurityException
      Computes the message authentication code (MAC) for the given data and returns it as a Base64 encoded string.
      Parameters:
      data - the data to compute the MAC for
      Returns:
      the computed MAC as a Base64 encoded string
      Throws:
      GeneralSecurityException - if an error occurs during MAC computation
    • computeAsBase64

      public String computeAsBase64(String data) throws GeneralSecurityException
      Computes the message authentication code (MAC) for the given data and returns it as a Base64 encoded string.
      Parameters:
      data - the data to compute the MAC for
      Returns:
      the computed MAC as a Base64 encoded string
      Throws:
      GeneralSecurityException - if an error occurs during MAC computation
    • computeAsBase64

      public String computeAsBase64(String data, Charset charset) throws GeneralSecurityException
      Computes the message authentication code (MAC) for the given data and returns it as a Base64 encoded string.
      Parameters:
      data - the data to compute the MAC for
      charset - the charset used to encode the data as bytes
      Returns:
      the computed MAC as a Base64 encoded string
      Throws:
      GeneralSecurityException - if an error occurs during MAC computation
    • verify

      public void verify(byte[] mac, byte[] data) throws GeneralSecurityException
      Verifies whether mac is a correct authentication code (MAC) for data.
      Parameters:
      mac - message authentication code
      data - data
      Throws:
      GeneralSecurityException - if the message does not validate