Is UUID.randomUUID() suitable for use as a one-tim

2019-02-02 23:42发布

As previous discussed, confirmation emails should have a unique, (practically) un-guessable code--essentially a one-time password--in the confirmation link.

The UUID.randomUUID() docs say:

The UUID is generated using a cryptographically strong pseudo random number generator.

Does this imply that the the UUID random generator in a properly implemented JVM is suitable for use as the unique, (practically) un-guessable OTP?

8条回答
淡お忘
2楼-- · 2019-02-03 00:27

It is perfect as one time password, as even I had implemented the same for application on which am working. Moreover, the link which you've shared says it all.

查看更多
你好瞎i
3楼-- · 2019-02-03 00:29

I think this should be suitable, as it is generated randomly rather than from any specific input (ie you're not feeding it with a username or something like that) - so multiple calls to this code will give different results. It states that its a 128-bit key, so its long enough to be impractical to break.

Are you then going to use this key to encrypt a value, or are you expecting to use this as the actual password? Regardless, you'll need to re-interpret the key into a format that can be entered by a keyboard. For example, do a Base64 or Hex conversion, or somehow map the values to alpha-numerics, otherwise the user will be trying to enter byte values that don't exist on the keyboard.

查看更多
登录 后发表回答