So a web app grabs data from a server with ajax. I'm interested to know whether there is some cryptography wizardy that would make sure the data came from that server. For example, someone can edit their hosts file and use a different server for the domain and pass different data to the web app without modifying it.
I'm thinking on something like this:
Server: data_to_send // stringified json integrity_code = getCode(data_to_send); //generates a code from the string. The server outputs data_to_send and integrity_code Then the client if (checkCode(data_to_send, integrity_code)) //all fine
I'm a total newbie to cryptography, but the idea is to have some secret algorithm on the server which no one can see and public algorithm on the client that determines if data is integral. Can something like that be done?