Elgg
Version 2.3
|
Public Member Functions | |
__construct (SiteSecret $site_secret=null) | |
Constructor. More... | |
getRandomBytes ($length) | |
Generate a string of highly randomized bytes (over the full 8-bit range). More... | |
getHmac ($data, $algo= 'sha256', $key= '') | |
Get an HMAC token builder/validator object. More... | |
getRandomString ($length, $chars=null) | |
Generate a random string of specified length. More... | |
areEqual ($str1, $str2) | |
Are two strings equal (compared in constant time)? More... | |
Public Attributes | |
const | CHARS_PASSWORD = 'bcdfghjklmnpqrstvwxyz2346789' |
Character set for temp passwords (no risk of embedded profanity/glyphs that look similar) More... | |
const | CHARS_HEX = '0123456789abcdef' |
Character set for hexadecimal. More... | |
Protected Member Functions | |
strlen ($binary_string) | |
Count the number of bytes in a string. More... | |
Definition at line 13 of file ElggCrypto.php.
ElggCrypto::__construct | ( | SiteSecret | $site_secret = null | ) |
Constructor.
SiteSecret | $site_secret | Secret service |
Definition at line 35 of file ElggCrypto.php.
ElggCrypto::areEqual | ( | $str1, | |
$str2 | |||
) |
Are two strings equal (compared in constant time)?
string | $str1 | First string to compare |
string | $str2 | Second string to compare |
Based on password_verify in PasswordCompat
Definition at line 278 of file ElggCrypto.php.
ElggCrypto::getHmac | ( | $data, | |
$algo = 'sha256' , |
|||
$key = '' |
|||
) |
Get an HMAC token builder/validator object.
mixed | $data | HMAC data or serializable data |
string | $algo | Hash algorithm |
string | $key | Optional key (default uses site secret) |
Definition at line 202 of file ElggCrypto.php.
ElggCrypto::getRandomBytes | ( | $length | ) |
Generate a string of highly randomized bytes (over the full 8-bit range).
int | $length | Number of bytes needed |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GEORGE ARGYROS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Our primary choice for a cryptographic strong randomness function is openssl_random_pseudo_bytes.
If mcrypt extension is available then we use it to gather entropy from the operating system's PRNG. This is better than reading /dev/urandom directly since it avoids reading larger blocks of data than needed.
No build-in crypto randomness function found. We collect any entropy available in the PHP core PRNGs along with some filesystem info and memory stats. To make this data cryptographically strong we add data either from /dev/urandom or if its unavailable, we gather entropy by measuring the time needed to compute a number of SHA-1 hashes.
Definition at line 72 of file ElggCrypto.php.
ElggCrypto::getRandomString | ( | $length, | |
$chars = null |
|||
) |
Generate a random string of specified length.
Uses supplied character list for generating the new string. If no character list provided - uses Base64 URL character set.
int | $length | Desired length of the string |
string | null | $chars | Characters to be chosen from randomly. If not given, the Base64 URL charset will be used. |
InvalidArgumentException |
Definition at line 228 of file ElggCrypto.php.
|
protected |
Count the number of bytes in a string.
We cannot simply use strlen() for this, because it might be overwritten by the mbstring extension. In this case, strlen() will count the number of characters based on the internal encoding. A sequence of bytes might be regarded as a single multibyte character.
Use elgg_strlen() to count UTF-characters instead of bytes.
string | $binary_string | The input string |
From PasswordCompat
Definition at line 311 of file ElggCrypto.php.
const ElggCrypto::CHARS_HEX = '0123456789abcdef' |
Character set for hexadecimal.
Definition at line 23 of file ElggCrypto.php.
const ElggCrypto::CHARS_PASSWORD = 'bcdfghjklmnpqrstvwxyz2346789' |
Character set for temp passwords (no risk of embedded profanity/glyphs that look similar)
Definition at line 18 of file ElggCrypto.php.