GLBasic forum

Codesnippets => Inline / 3rd party => Topic started by: Kitty Hello on 2010-Oct-12

Title: ENCRYPT$ - php backend
Post by: Kitty Hello on 2010-Oct-12

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.

[attachment deleted by admin]
Title: Re: ENCRYPT$ - php backend
Post by: trucidare on 2010-Oct-12
Cooolio :D
Title: Re: ENCRYPT$ - php backend
Post by: Moru on 2010-Oct-14
Nice, thanks!
Title: Re: ENCRYPT$ - php backend
Post by: Alex_R on 2016-Mar-16

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]
$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);
Title: Re: ENCRYPT$ - php backend
Post by: spacefractal on 2016-Mar-16
Use urldecode/encode functions first to convert it to base64 strings. Then it's should work.
Title: Re: ENCRYPT$ - php backend
Post by: Alex_R 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?
Title: Re: ENCRYPT$ - php backend
Post by: kanonet on 2016-Mar-17
In GLBasic program, did you use URLDECODE$ after DECRYPT$?
Title: Re: ENCRYPT$ - php backend
Post by: Alex_R 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.
Title: Re: ENCRYPT$ - php backend
Post by: spacefractal 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):