Code example for SecretKeySpec

  private boolean verifyMac(byte[] messageBytes)
      throws InvalidEncryptedSignalException, IOException, 
             NoSuchAlgorithmException, InvalidKeyException 
    byte[] macKey     = getMacKey();
    SecretKeySpec key = new SecretKeySpec(macKey, "HmacSHA1");
    Mac mac           = Mac.getInstance("HmacSHA1");
    mac.update(messageBytes, 0, messageBytes.length-MAC_LENGTH);
    byte[] ourDigestComplete = mac.doFinal();
    byte[] ourDigest         = new byte[10];
    byte[] theirDigest       = new byte[10];
    System.arraycopy(ourDigestComplete, 10, ourDigest, 0, ourDigest.length);
    System.arraycopy(messageBytes, messageBytes.length-MAC_LENGTH,
                     theirDigest, 0, theirDigest.length);
    return Arrays.equals(ourDigest, theirDigest);
Connect your IDE to all the code out there  Get Codota for Java