# 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:

1. Choose messages of their own liking;
2. Cause you to compute these messages' tags;
3. 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.

HMAC-SHA256 is extremely safe. In the question's use, the key is large (48 characters, likely >160 bits of entropy). From a theoretical standpoint, everything checks.

HMAC is demonstrably resistant (to 128-bit level) even if an adversary can obtain the MAC of chosen messages, under weak hypothesis for SHA-256 (see M. Bellare: New Proofs for NMAC and HMAC: Security without Collision-Resistance, also in proceedings of Crypto 2006); therefore, the predictability of UUID+Time is a non-issue.

Real concerns should be about the overall protocol; and implementation-related. Like (for the later), can the machine be pwned, is the key entered with a wireless keyboard..