There is a particular string (URL) that I need to send from my webserver to the browser. The browser will need to inspect the string and later send it back unmodified (aka request the resource that the URL is pointing to). If the browser could modify the string, it would be a security risk. So I need to make sure that the string has not been tampered with.
To do that I need to provide some kind of checksum in the URL which the server can validate, but which the client cannot generate. Two approaches come to mind:
- Append some secret string (aka "salt", preferably pretty lengthy and random) to the URL and hash it with SHA1. Since the client doesn't know the secret string, he shouldn't be able to generate the hash for a different URL. My worry: Since he can gather several of these server-side generated URLs (on the order of a few dozen), maybe he can reverse-engineer the salt?
- The same as before, but also encrypt it with AES. This is slower, but there's actual cryptography involved. My worry: SHA1 generates 160 bits, while AES works with 128-bit blocks. So the hash will need to be padded, probably with zeroes. Also, there are just 2 blocks. Will that not allow the attacker to discover the key easily?
Is any of these approaches really secure? Or should I try to do something else entirely?