Class Webhook.Util

  • Enclosing class:
    Webhook

    public static final class Webhook.Util
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Util()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String computeHmacSha256​(java.lang.String key, java.lang.String message)
      Computes the HMAC/SHA-256 code for a given key and message.
      static long getTimeNow()
      Returns the current UTC timestamp in seconds.
      static boolean secureCompare​(java.lang.String a, java.lang.String b)
      Compares two strings for equality.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • computeHmacSha256

        public static java.lang.String computeHmacSha256​(java.lang.String key,
                                                         java.lang.String message)
                                                  throws java.security.NoSuchAlgorithmException,
                                                         java.security.InvalidKeyException
        Computes the HMAC/SHA-256 code for a given key and message.
        Parameters:
        key - the key used to generate the code.
        message - the message.
        Returns:
        the code as a string.
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.InvalidKeyException
      • secureCompare

        public static boolean secureCompare​(java.lang.String a,
                                            java.lang.String b)
        Compares two strings for equality. The time taken is independent of the number of characters that match.
        Parameters:
        a - one of the strings to compare.
        b - the other string to compare.
        Returns:
        true if the strings are equal, false otherwise.
      • getTimeNow

        public static long getTimeNow()
        Returns the current UTC timestamp in seconds.
        Returns:
        the timestamp as a long.