How secure is HMAC SHA256 I have a message (UUID) in this form 406a5830-2a6a-11e6-bdf4-0800200c9a66. I also use a secret key for example 0987YGN.?NBVFRTY876JOPOIUHJ$$bvcfghjKFDFGH876TH$. Every 3 seconds I use the java function below to crypt the UUID+Time with the secret key using the SHA 256 function. I publish the new result on the internet. As I have a new hash every 3 second, it's easy for everyone to collect a big numbers of hash.And as the difference between every UUID is always 3000 ms, maybe this could make it easier for the hacker to crack the key. My question is: Would it be possible for a person to guess the secret key or the message I am using? Is it possible to calculate the probability that this system get hacked ?

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;

public class ApiSecurityExample {
  public static void main(String[] args) {
    try {
     String secret = "0987YGN.?NBVFRTY876JOPOIUHJ$$bvcfghjKFDFGH876TH$";
     String message = "406a5830-2a6a-11e6-bdf4-0800200c9a66"+System.currentTimeMillis();

     Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
     SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
     sha256_HMAC.init(secret_key);

     String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(message.getBytes()));
     System.out.println(hash);
    }
    catch (Exception e){
     System.out.println("Error");
    }
   }
}
As I have a new hash every 3 second, it's easy for everyone to collect a big numbers of hash.  And as the difference between every UUID is always 3000 ms, maybe this could make it easier for the hacker to crack the key.


You might be reassured to read up on the security requirements that MACs are designed for.  Chapter 9 of the Handbook of Applied Cryptography is a good, freely available source.  (Section 9.2.2 is the most relevant.)

But to make this short, good MACs are expected to resist adaptive chosen text attacks, where the attacker doesn't just see the tags, they get to:


Choose messages of their own liking;
Cause you to compute these messages' tags;
Pick messages based on what they learn from earlier ones.


A MAC is considered broken if an attacker in that scenario can learn enough to successfully forge tags for other messages than the ones they caused you to authenticate.  That's a scenario much, much more adverse than the one you describe, where they only passively see tags (and no messages).  

So as long as you can keep the key secret, you probably have much bigger security concerns than this.