views:

191

answers:

4

When I use some of php's encryption functions, I end up getting a few characters I don't want (+, /, =). The problem is that my application doesn't allow these in the url. I'm wondering if there's a good way of encrypting an integer and having only alphanumeric characters in the result? I'm trying to pass some data through the url. I know it's possible to do some workarounds (put data in database and pass the id to the row or something), but I really want to try it this way.

Ideas?

+1  A: 

You're looking for base_convert().

Ignacio Vazquez-Abrams
I don't think that's technically encrypting. It might be too easy for a user to figure out the original integer.
Matthew
Matthew, base64_encode (as mentioned by you above) is not encryption either. That's just encoding.
halfdan
A: 

I use sh1 and never got nothing but numbers and letter's...

http://www.php.net/manual/en/function.sha1.php

Maybe it's your solution...

Zuul
Isn't that only one way? I need it to be two way encryption.
Matthew
if by "two way" you mean "encrypt and decrypt", I use sh1 to encrypt pwd's for login systems...When verifying, I grab the inputed value and sh1(it) before comparison... But I don't know if this solves your problem!
Zuul
A: 

I believe base64_encode then send data and then base64_decode the other side.

I "think" base64 encoding is perfectly file for URI's

RobertPitt
+1  A: 

I would rethink your problem. You never, ever want to pass sensitive data in the URL query. There is already a mechanism for collecting sensitive data over the web - it's called SSL. If you need to get sensitive data from the user, accept it as POST data and use SSL.

If you absolutely must do this (don't), you would do it by base64'ing the encrypted message and being very careful about key safety.

alexantd
There we go. I need to base64_encode the already encrypted message. I still need to get rid of the padding '=' at the end of the string. I'll figure that out though. And don't worry it's not *that* sensitive.
Matthew
Use the URL-safe version of the Base64 encoder.
ZZ Coder