duancheng8000 2019-02-28 11:35
浏览 213

sha256有多独特? 是否足以生成比db中的64个字符长唯一编号自动递增主索引id更多的唯一结果?

I would like to hash a numeric string because I do not want people to know the exact number for various security and other reasons. How about doing it so?

        $number = X; // get my number from wherever
        $secret     = mt_rand(); // or maybe another randomly generated secret!?
        $hash       = hash_hmac("sha256", $number, $secret); // or maybe another algo!?

So when I want to retrieve the number, I will just compare the hash generated with the hash returned from the app, which is already stored in the database, and I can lookup the number by this hash. Would this be unique enough to handle a number larger than 64 characters? And, yes, I am serious. This is for statistical data and it will get huge... huge numbers, most probably more than 64 characters long.

Regards!

  • 写回答

0条回答 默认 最新

    报告相同问题?