0
$\begingroup$

I want to generate some tokens for client as http cookie

can I md5 them with salt and then use "<random token>"+"<md5>" as the token for they can be verified in a cheap way

is it safe?

$\endgroup$

1 Answer 1

1
$\begingroup$

What you're referring to is a message authentication code, or MAC. In general, you should avoid using Merkle-Dåmgard hash functions (such as MD5, SHA-1, or SHA-2) with a salt or key as a MAC because of length extension attacks, among others.

If you need to generate a MAC of data like this, you should use HMAC with a secure hash function (e.g., SHA-256), KMAC (related to SHA-3), or BLAKE2 with its keyed mode. If you're not sure what to do, HMAC-SHA-256 is a fine default.

While using MD5 or SHA-1 with HMAC to secure a message doesn't have known practical attacks, there is no good reason to use either MD5 or SHA-1 in a new design, and you should avoid them altogether for any purpose.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.