public boolean isValid ( String apiKey ) throws HelloSignException { if ( apiKey == null || apiKey == "" ) { return false ; } try { Mac sha256HMAC = Mac . getInstance ( HASH_ALGORITHM ) ; SecretKeySpec secretKey = new SecretKeySpec ( apiKey . getBytes ( ) , HASH_ALGORITHM ) ; sha256HMAC . init ( secretKey ) ; String data = String . valueOf ( getLong ( EVENT_TIME ) ) + getType ( ) ; String computedHash = bytesToHex ( sha256HMAC . doFinal ( data . getBytes ( ) ) ) ; String providedHash = getString ( EVENT_HASH ) ; return computedHash . equalsIgnoreCase ( providedHash ) ; } catch ( InvalidKeyException e ) { throw new HelloSignException ( "Invalid API Key (" + e . getMessage ( ) + "): " + apiKey ) ; } catch ( IllegalArgumentException e ) { throw new HelloSignException ( "Invalid API Key (" + e . getMessage ( ) + "): " + apiKey ) ; } catch ( NoSuchAlgorithmException e ) { throw new HelloSignException ( "Unable to process API key" , e ) ; } }
Returns true if the event hash matches the computed hash using the provided API key .