php hash form string to integer

前端 未结 3 837
死守一世寂寞
死守一世寂寞 2020-12-17 15:34

Does PHP have a built in function for doing string to integer hashes, something that\'s difficult to reverse?

Now, I know I can probably get away with doing an md5,

3条回答
  •  生来不讨喜
    2020-12-17 16:00

    I think you are on the right path in approaching this problem in two steps.

    First, you should probably stick with the md5 hash to fulfill your "difficult to reverse" requirement.

    Second, you could take the md5 output as input to your "convert this to an integer" function.

    for the second part, what are you going after exactly? Does it have to be an integer? Or just printable characters? if you are just looking to convert your hash into something you can store in a database, transmit over the wire, or some other reason the md5 string won't do, the convertuuencode function might work for you: http://us.php.net/manual/en/function.convert-uuencode.php

    Another roundabout hackish approach would be to get the binary value of your hash, and convert it to a decimal using: http://us.php.net/manual/en/function.bindec.php although, i've never tried this and am not sure if it would work like you want it to.

提交回复
热议问题