short generated keys may end with trailing = #367

Closed
opened 2026-10-04 23:54:49 +02:00 by adam · 0 comments
Owner

Because of the nature of base64 encoding, strings are "padded" with trailing "=". So in str_replace(array('+', '/'), '', base64_encode(openssl_random_pseudo_bytes($size))) we may have less than $size chars, when $size is small and if we have some +/ in the returned value of openssl_random_pseudo_bytes. To avoid this problem, the simplest solution is to ask a "bigger" string to openssl_random_pseudo_bytes.

Because of the nature of base64 encoding, strings are "padded" with trailing "=". So in str_replace(array('+', '/'), '', base64_encode(openssl_random_pseudo_bytes($size))) we may have less than $size chars, when $size is small and if we have some +/ in the returned value of openssl_random_pseudo_bytes. To avoid this problem, the simplest solution is to ask a "bigger" string to openssl_random_pseudo_bytes. <!-- github-sync-id:116206807 -->
adam closed this issue 2026-10-04 23:54:49 +02:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#367