Re: using CRYPT but restrict alpha-numeric
| From: | Christoph M. Becker | Date: | Tue, 07 Dec 2021 23:50:57 +0000 |
| Subject: | Re: using CRYPT but restrict alpha-numeric | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-327861@lists.php.net to get a copy of this message | ||
On 08.12.2021 at 00:11, gordonisnz@gmail.com wrote:
> I'm looking at the various CRYPT / one-way encryption commands and i
> was wondering if there is a way to create a crypt but restrict output
> to alpha-numeric (a to z, A to Z and 0-9) without the special
> characters ?
>
> Basically ive got a starting reference - numeric over 10,000,000 and
> other numbers and want to do a crypt (or something) but exclude
> special characters from the crypt result.
>
> The best I can think of is to do a crypt (or whatever) etc and then do
> a preg_replace to remove the special characters etc..
>
> The result will be shorter (length), but will be an alpha-numeric crypt.
Yep, it would be shorter, but doing it would be a bad idea. Instead,
*map* the cryptographic value to the desired value. In your case,
bin2hex() would do, but a (variant of) base64_encode() might be
acceptable as well, and could save memory/bandwidth.
I also suggest to read up on that "crypt" thing. :)
--
Christoph M. Becker