r/programming • • Nov 25 '15

Don't use the OWASP PHPSec Crypto Library

https://gist.github.com/paragonie-scott/91893fdb18ee4d1a1b95
38 Upvotes

80 comments sorted by

View all comments

Show parent comment

2

u/beerdude26 Nov 25 '15

A CSPRNG only in 2016. Good job, PHP. Real security-minded like

2

u/sarciszewski Nov 25 '15

A CSPRNG only in 2016. Good job, PHP. Real security-minded like

PHP has CSPRNG interfaces in 5.3+ or 5.x with the mcrypt extension, but it's clunky and unreliable (OpenSSL). On Unix-based OSes you can also read from /dev/urandom.

What PHP 7 offers is a simple and secure interface:

  • string random_bytes(int $howMany)
  • int random_int(int $min, int $max)

It also happens to leverage getrandom(2) if you're on a newer version of Linux.

If you want to use the same interface in PHP 5, I maintain random_compat.

But y'know what? I'm disappointed that it took this long to happen.