Replace OpenSSL with native CSPRNG for token generation #64
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR deprecates the usage of
openssl_random_pseudo_bytesin favor of the nativerandom_bytesfunction.Key Changes:
Security Standard Upgrade (CSPRNG): Switched to
random_bytes, which is currently considered the industry state-of-the-art for generating cryptographic entropy in PHP. Unlike OpenSSL, it is native to the language and provides a fail-closed mechanism (throws anExceptioninstead of returning weak data if entropy is insufficient).Length Accuracy: Implemented a calculation logic to ensure the generated hex string matches exactly the requested
$length.References & Resources:
Why this change is necessary
openssl_random_pseudo_bytesrelies on the OpenSSL extension availability and historically required manual verification of the$crypto_strongboolean to avoid silent failures.random_bytesabstracts access to the OS's entropy source (e.g.,/dev/urandom) securely and natively.