Re: using CRYPT but restrict alpha-numeric
[email protected] (Ashley Sheridan)
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
On 07/12/2021 23:11, [email protected] wrote: > Hello. > > 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. > > -- > > Gordon. > If you only want it limited to the 36 characters, you could base64 encode it after it's encrypted? This will increase the size of the encrypted data, but not knowing what you're doing, it would be impossible to say whether or not this is a problem for you. I'd advise against removing characters from the encrypted string though, as this effectively increases the chance for collisions. -- Ashley Sheridan https://www.ashleysheridan.co.uk