package app.utils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.util.DigestUtils; @Component public class SaltedCookie { @Value("${backend.auth.salt}") private String salt; @Value("${backend.secret_key}") private String secret_key; public String Hashed(String value) { return DigestUtils.md5DigestAsHex(String.format("%s+%s", value, salt).getBytes()); } public boolean Validate(String value, String hashed_value) { return Hashed(value).equals(hashed_value); } public boolean Validate(Long value, String hashed_value) { return Validate(value.toString(), hashed_value); } public boolean ValidateSecretKey(String secret_key) { return this.secret_key.equals(secret_key); } }