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");
}
}
}