SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cipher with no special chars?

    Hi there,

    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?

    Thanks
    Jacob

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    secure webapps for all Aleksejs's Avatar
    Join Date
    Apr 2008
    Location
    Riga, Latvia
    Posts
    755
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    urlencode the output of cipher
    and when received
    urldecode url parameter and then decrypt

  5. #5
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    %08%85%2F%89R%91%7F%0A

    in the URL.

  6. #6
    secure webapps for all Aleksejs's Avatar
    Join Date
    Apr 2008
    Location
    Riga, Latvia
    Posts
    755
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hex value perhaps?

  7. #7
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  8. #8
    secure webapps for all Aleksejs's Avatar
    Join Date
    Apr 2008
    Location
    Riga, Latvia
    Posts
    755
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need bin2hex, there is no built in hex2bin though - so you use:
    $binary_representation = pack('H*', $hexvalue);

  9. #9
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    awesome! thanks a lot mate!

  10. #10
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  11. #11
    secure webapps for all Aleksejs's Avatar
    Join Date
    Apr 2008
    Location
    Riga, Latvia
    Posts
    755
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, Blue!
    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.

  12. #12
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  13. #13
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  14. #14
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    220
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    base64_encode() may be faster if all u need is just to get rid of 'special character in the encryption output'


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •