Why is the private key used twice when creating a security hash?

One of the payment solutions for websites suggests using the private key twice when creating a security hash for payment links. This approach serves as a crude protection against length extension attacks, which primarily affect hash functions built using the Merkle-Damgård construction.

In a length extension attack, an attacker who knows the hash, secret, and message can easily forge a new hash by appending additional data. By including the secret key at the end of the message, this type of attack is thwarted because the attacker does not know the secret key and cannot create a valid hash.

However, it’s important to note that there are proven secure cryptographic constructs, such as HMAC, specifically designed for message authentication. The use of a home-grown construct like this suggests that the authors of this service may not be well-versed in cryptography. It raises concerns about the security of their cryptography practices.

Leave a Reply

Your email address will not be published. Required fields are marked *