BASIC

Author Topic: ENCRYPT$ - php backend  (Read 5469 times)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10651
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
ENCRYPT$ - php backend
« on: 2010-Oct-12 »
Hi,

this is the PHP code you must use to generate the same results as with ENCRYPT$/DECRYPT$.

Please - use _this_ version, not any original copy you can find.

Offline trucidare

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1377
  • Bachelor of Fail
    • View Profile
Re: ENCRYPT$ - php backend
« Reply #1 on: 2010-Oct-12 »
Cooolio :D
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1749
    • View Profile
    • Homepage
Re: ENCRYPT$ - php backend
« Reply #2 on: 2010-Oct-14 »
Nice, thanks!

Offline Alex_R

  • Mr. Polyvector
  • ***
  • Posts: 237
    • View Profile
    • Axro Digital
Re: ENCRYPT$ - php backend
« Reply #3 on: 2016-Mar-16 »
Hello!

Does anyone know if this PHP code can be used with non-english characters and Windows-1252 encoding?

Whenever I try to encrypt something like "campeón" ('champion' in Spanish) I get an encrypted string which is a different string than the string GLBasic would give with ENCRYPT$ (so that is not good). But also, when I try to decrypt this encrypted string with GLBasic the app crashes, or if I try to decrypt the string using the PHP function it returns nothing. The same PHP code works perfectly if I don't use special characters (but that is not a solution for me) or if I use UTF-8 instead of Windows-1252, but I think we need to use Windows-1252 if we want to use the encrypted string in GLBasic, don't we?

Any help or hint would be much appreciated.

The PHP code I use to test (in case you see something there that I don't):
Code: GLBasic [Select]
include('blowfishEncrypt.php');
$obj = new MyBlowfish("MyStrongPswd");
$test = iconv("UTF-8","Windows-1252//TRANSLIT", "campeón");
$testEnc = $obj->encryptString($test);
$testDec = $obj->decryptString($testEnc);
echo("Encrypted: ".$testEnc."<br>Decrypted: ".$testDec);
 

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3326
    • View Profile
    • Space Fractal
Re: ENCRYPT$ - php backend
« Reply #4 on: 2016-Mar-16 »
Use urldecode/encode functions first to convert it to base64 strings. Then it's should work.
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline Alex_R

  • Mr. Polyvector
  • ***
  • Posts: 237
    • View Profile
    • Axro Digital
Re: ENCRYPT$ - php backend
« Reply #5 on: 2016-Mar-17 »
Thank you for your answer, spacefractal.

Unfortunately, it doesn't seem to completely solve my problem: now first I use urlencode in PHP, then encrypt the string in PHP, and finally send the encrypted string to GLBasic where I get "campe%C3%B3n" instead of "campeón". My GLBasic app doesn't crash, but the resulting texts are unreadable. Is there any other way?

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: ENCRYPT$ - php backend
« Reply #6 on: 2016-Mar-17 »
In GLBasic program, did you use URLDECODE$ after DECRYPT$?
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Alex_R

  • Mr. Polyvector
  • ***
  • Posts: 237
    • View Profile
    • Axro Digital
Re: ENCRYPT$ - php backend
« Reply #7 on: 2016-Mar-18 »
Thank you, kanonet. I didn't know there was a URLDECODE$ instruction in GLBasic!

Indeed, I did not use that instruction on my tests. I was hopping to achieve in PHP the very same encryption I get from ENCRYPT$ in GLBasic (I wanted to obtain the same encrypted file no matter what language I used). But it seems that, in order to do so, I'll have to modify my GLBasic code too and insert a URLENCODE$/URLDECODE$ instruction before/after encrypting my texts, respectively. Thank you again for the hints.

Although I assume this is not the optimum choice. Since GLBasic is already capable of encrypting and correctly decrypting "campeón" without having to previously use URLENCODE$, this PHP instruction should be able to do the same, right? Maybe there is a way to update this blowfish.php file so that it can encrypt non-english Windows-1252 characters too?

Anyway, thank you all, again, for your input.

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3326
    • View Profile
    • Space Fractal
Re: ENCRYPT$ - php backend
« Reply #8 on: 2016-Mar-18 »
the main issue, me thinks is the server using a different charset page, than that one you using. To prevent chars to been changed, you should only uses English safe chars, which is why you should do a URLDECODE/ENCODE first to prevent various issues.

in php, you can use those (im havent tested it):
http://php.net/manual/en/function.urlencode.php
http://php.net/manual/en/function.urldecode.php

Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.