Transaction Data Signing

I need an idea to develop a very secure algorithm to authenticate online operations using PHP in the server and an Android app in the user's device.

What is the idea?

The user try to login in the system. The server sends a confirmation request to user's device (Android).

The user sees the date, country, city, IP, browser and OS in the app, all about the login try, and if all this informations match, he can clicks on confirm. The app will generate an 8 decimal digit token based in this informations and send it to server, the server will try to generate a token with the same informations and if both tokens match, the server accept the login try.

This is just one possible operation.

What do I need?

An universal algorithm to authenticate any online operation.


function generateRandonTokenUsingNParameters(){
    $args = func_num_args();
    $token = ""; //Start token

    for($i=0; $i < $args; $i++){
        $token = CRAZY_MATH_USING_ALL_PARAMETERS_TO_GENERATE_8_DIGITS_TOKEN($token, func_get_arg($i));

    return $token; //Final token based in all informations of the operation


$date = "2014-05-30 01:02:00"
$ip = "";
$browser = "Chrome";
$city = "Los Angeles";
$country = "USA";
$os = "Windows";
$android_app_local_seed = "698dc19d489c4e4db73e28a713eab07b"; //each user have a different seed in his app

echo generateRandonTokenUsingNParameters($date, $ip, $browser, $city, $country, $os, $android_app_local_seed);


P.S.: I need an 8 decimal digit numeric token. Because if the user does not have internet connection, he can read the operation's details using QR Code and he will need insert the token in the system manually.

  • 1
    Firstly, is there any reason why a cryptographic hash of a string concatenation of these parameters wouldn't be suitable? Secondly, it seems as though the user could arbitrarily manipulate just about all of these parameters and log in - although I guess the local seed is designed to prevent that? Why do you need all the other info, why couldn't you hash the seed?
    – thexacre
    May 30, 2014 at 4:26
  • @thexacre yes, the seed prevents someone that knows the algorithm from generating tokens that could be used to login in any account. I need all the other informations to sign the operation. The token can be used just by the person trying to login using that ip, browser and os.
    – Lucas NN
    May 30, 2014 at 4:51
  • HMAC with a shared key is what you'd want to use. Don't forget to use a nonce or a timestamp as part of input. It is ok to only use the first X bits of you only need that degree of bruteforce resistance (because your server rate limits the requests)
    – Natanael
    Nov 29, 2014 at 7:26

1 Answer 1


Stringify the sent information in a standard way, take the SHA256 hash, sign it with the private half of the key-pair that is genned for the handset when the application is installed (the public half is sent to the server at enrollment time).

Most importantly, HMAC is easy to do wrong because it is crypto and crypto is really hard to do right (even Ron Rivest -- the R in RSA, and possibly one of the top expert in crypto -- can come up with something like RC4 which has some protocol-level weaknesses_. DO NOT ROLL YOUR OWN CRYPTO. I would bet money you will not do it correctly. Instead, use existing algorithms, existing methodologies, existing libraries. HMAC using SHA256+ECDSA is well understood and has been tested. If you go with EC crypto for your public-private key-pair-generation and signing, use a curve that is well known, such as the NIST curves, since they have the most scrutiny and have highly funded cryptanalytic research by the federal government.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .