title: How to verify HMAC java
body: <p>I've got the following code to compute Hmacs with a password: </p>
  
  <pre><code>public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException 
  {
    String password = "password123";
    SecretKeySpec keySpec = new SecretKeySpec(password.getBytes(), "HmacSHA1");
  
    Mac mac = Mac.getInstance("HmacSHA1");
    mac.init(keySpec);
  
    byte[] result = mac.doFinal("This is a test string".getBytes());
  
    System.out.println(new Base64().encodeAsString(result));
  }
  </code></pre>
  
  <p>But I can't figure out how to verify it with a password, I'm reading the Java documentation <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/security/crypto/CryptoSpec.html#Concepts" rel="nofollow">here</a> but i can't  seem to find a verify function or anything, the section on HMACs is quite short. </p>
  
  <p>How do i verify the HMAC with the password?</p>