Are there any one-way hashing functions available in native JavaScript?

前端 未结 4 1434
滥情空心
滥情空心 2020-12-13 09:39

I\'d like to be able to create unique tokens* for users based on a hashed string. I know I could, for example, use a md5() library but as the purpose is not cryptographic I

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 09:52

    Nothing is available in native JavaScript. You could use something like Murmurhash. There's a JavaScript implementation here: https://github.com/garycourt/murmurhash-js. I haven't used it though so can't vouch for it.

    Update: now there are multiple Murmurhash3 implementations available in JavaScript. However, many of them have problems encoding strings to bytes and can produce different results compared to the reference C++ implementation. You can read an analysis on this here, the murmurhash3js-revisited library implements all three variants of the function and conforms to the reference.

提交回复
热议问题