NetTalk Central

Author Topic: PHP <> NT encrypt and decrypt  (Read 6343 times)

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
PHP <> NT encrypt and decrypt
« on: June 25, 2019, 02:07:22 PM »
Hi, I have a php page that I use as a http server, it returns a plain xml
I need to crypt this xml, or de contentes of each tag, in PHP, read the crypt xml with NT, decrypt it and use it.
Any idea of what crypt function may be compatible with Nt ST or Cryptonite procs?
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: PHP <> NT encrypt and decrypt
« Reply #1 on: June 25, 2019, 09:31:04 PM »
Hi Alberto,

so many questions :)

>> I have a php page that I use as a http server, it returns a plain xml

So this is a PHP page running under the NetTalk server? Or running under another server?

>> I need to crypt this xml,

You need to encrypt it on the server, before sending it to the client?
the client will need to decrypt it? Using Clarion code? Using some other code?

>> I need to encrypt this xml in PHP.

Ok, so on the server side you want to encrypt the XML before sending it to the client? (why? it's already encrypted over the TLS connection...?) Presumably you have a variety of PHP options you can use for this...

>> read the crypt xml with NT,

So with the Webclient - presumably you'll make a simple GET request to the server, over TLS? Presumably you will authenticate the client with the server? (so I'm not sure what encrypting the XML will achieve?)

>> Any idea of what crypt function may be compatible with Cryptonite?

(StringTheory does not do encryption, so that's not part of this discussion.)

I'm no expert on PHP (I can barely spell PHP) but I'm guessing "pretty much everything" would be compatible, especially if you read this;
https://www.capesoft.com/docs/CryptoNite/CryptoNite.htm#Interoperability

Cheers
Bruce






DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: PHP <> NT encrypt and decrypt
« Reply #2 on: June 26, 2019, 02:23:38 AM »
Alberto,

I had some success using Blowfish encryption but I don't know if that would apply with PHP+XML.

There's good examples of Blowfish in the Cryptonite shipped examples.

Just a thought.

Don
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: PHP <> NT encrypt and decrypt
« Reply #3 on: June 26, 2019, 01:02:11 PM »
Is a simple PHP page, it is not served by NT
This is the PHP code Im using to encrypt with blowfish:

Code: [Select]
$cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CFB, '');

$iv =  '12345678';
$key256 = '1234567890123456ABCDEFGHIJKLMNOP';
$cleartext = 'The quick brown fox jumped over the lazy dog';

if (mcrypt_generic_init($cipher, $key256, $iv) != -1)
{
// PHP pads with NULL bytes if $cleartext is not a multiple of the block size..
$cipherText = mcrypt_generic($cipher,$cleartext );
mcrypt_generic_deinit($cipher);

echo("\n 256-bit blowfish encrypted  (base64): ".base64_encode($cipherText));
}

You can test it at: http://www.armisoftware.com/winsami/winsamitestc.php
obtaining:
Code: [Select]
iv: 12345678
 key256: 1234567890123456ABCDEFGHIJKLMNOP
 clearText: The quick brown fox jumped over the lazy dog
 256-bit blowfish encrypted  (base64): zxQo/gtJN6i9vIegyt/IWzkh5tR/TK17YWk8I+npKzPh/0H1MuTBRNl71lM=

If you run the Cryptonite example using the same IV, key256 and base64 encryption it does not decode.

May be Cryptonite works on other way?
-----------
Regards
Alberto

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: PHP <> NT encrypt and decrypt
« Reply #4 on: June 27, 2019, 02:18:22 AM »
Hello Alberto,

I'm about to fire up my dev machine.  I'll test Cryptonite with the sample you posted.

Cryptonite's Blowfish is pretty straight forward so I suspect it should work. 

I'll post back after testing.

Don
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: PHP <> NT encrypt and decrypt
« Reply #5 on: June 27, 2019, 02:26:36 AM »
Don't use blowfish - that's a "non standard" algorithm (and a non-standard implementation).

Rather use something like AES256. That's standard and uses the Windows Crypto API.

cheers
Bruce

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: PHP <> NT encrypt and decrypt
« Reply #6 on: June 27, 2019, 04:42:54 AM »
Hello Alberto,

Also, it appears many (most) of the methods used in your example were depreciated as of PHP Ver 7.1 or so.  Don't know if that's relevant.

From what what I've seen on the various PHP forums, blogs, etc., they pretty much say what Bruce just said.

Good luck,

Don
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: PHP <> NT encrypt and decrypt
« Reply #7 on: June 27, 2019, 05:38:00 AM »
Sory about the OT.
Will post it in the News group.
-----------
Regards
Alberto