Eugene Shubin
Eugene Shubin

Reputation: 23

Key generation algorithm in Riak

Riak has an API, which allows to create a record and unique key would be generated on server. What algorithm is used for server-side key generation in Riak? Is the length configurable? Is it securely random? Can it be used as authentication token?

Upvotes: 0

Views: 51

Answers (1)

Joe
Joe

Reputation: 28326

The generated key is the base 62 representation of the sha hash of an erlang reference and the current timestamp. The code is available here

unique_id_62() ->
    Rand = sha(term_to_binary({make_ref(), os:timestamp()})),
    <<I:160/integer>> = Rand,
    integer_to_list(I, 62).

Personally, I would not consider this to be sufficiently secure to use as a persistent authentication token.

Upvotes: 1

Related Questions