I need to encrypt something but I do not want any special character in the encryption output. Only letters and numbers. Is there any cipher that can achieve this?
Is there a reason why you're looking to change the encryption method rather than your approach? It's so pointless to put encryption and charset in the same sentence, think about your reasoning about this request.
Hint: if it's a database insert problem, take a look at PDO.
hex value perhaps?
urlencode the output of cipher
and when received
urldecode url parameter and then decrypt
Well I have some URL parameters that I do not want to be too obvious to the users, and to make the URL a bit more clean than having a lot of special characters up there.
Yes, yes, I do know that it would work without any problems. But I do like to get something a bit cleaner than for example
in the URL.
That's pretty clever.
Though is there any way that I can encrypt via cipher, take take the hex value of that. And then decrypt that again?
Using bin2hex and hexdec doesn't work.
You need bin2hex, there is no built in hex2bin though - so you use:
$binary_representation = pack('H*', $hexvalue);
awesome! thanks a lot mate!
1.) It's a bad idea to use GET method to propagate (larger set of) data.
2.) GET method has a limit on amount of data you can send, use POST.
3.) Hexing something inflates the data by the factor of 2, you'll hit the limit of the GET method extremely fast and you'll wonder how your thing won't decrypt.
4.) Using hexed data to obfuscate something is generally bad idea because it's extremely easy to notice it.
I agree with first three statements. The last one I think does not apply here, since he passes output of cipher - hexing serves here merely as an encoding not obfuscation.
Thanks for the responses.
As I'm only encrypting numbers, and a number like 12345678910111212345678910111212389172398716273091238091 returns: 58e03717907c3cdc13df1d619e0422949c5b70ea189ecf78
and that's a number I really don't expect to get up to, and I think that I should be able to use the GET method in this case.
I'm assuming you're passing some sort of an ID trough the URL and you don't want users to guess numbers by changing the query string.
Well, don't you think that encrypting / decrypting or/and hexing the number is a little too extreme? As I said, change of approach to your problem might be a better solution.
base64_encode() may be faster if all u need is just to get rid of 'special character in the encryption output'