ESP32 + PHP string encryption

Hi, everyone.
I want to make an encrypted string communication between my esp32 and PHP. I am using the HTTPClient.h library (HTTPS connection).
Every request I send parameters and I want to encrypt them on my esp32 and decrypt them on my PHP script. My PHP also sends back some data to the esp32 so I want it to be encrypted too. I've tried so many libraries and searched everywhere for information but I haven't found anything yet. I tried using mbedtls AES encryption which I wasn't able to work with on my PHP. I tried the XXTEA library for both the ESP32: https://github.com/boseji/xxtea-iot-crypt and the PHP: GitHub - xxtea/xxtea-php: XXTEA encryption algorithm library for PHP. but the encryption values were different. On XXTEA I used the key "ENCRYPTION KEY" and encrypted the string "HELLO WORLD" both on PHP and my esp32 and those were the results:
PHP -> T1YNYC4P4R2Y5eCxUqtjuw==
ESP32 -> 35bd3126715874f741518f4d
My esp32 sketch looks like this:

#include <xxtea-iot-crypt.h>

void setup() {
  Serial.begin(115200);
}

void loop() {
  String plaintext = "HELLO WORLD";

  // Set the Password
  xxtea.setKey("ENCRYPTION KEY");

  // Perform Encryption on the Data
  Serial.print(F(" Encrypted Data: "));
  String result = xxtea.encrypt(plaintext);

  Serial.println(result);

  // Perform Decryption
  Serial.print(F(" Decrypted Data: "));
  Serial.println(xxtea.decrypt(result));
  delay(2000);

}

My PHP code looks like this:

require_once('xxtea.php');
$str = "HELLO WORLD"
$key = "ENCRYPTION KEY";
$encrypt_data = xxtea_encrypt($str, $key);
error_log($encrypt_data); //for outputting the data

I even tried to base64 encode the result from the esp32 because it looks like hex for me but it still wasn't the same.
I have opened two issues, one on GitHub: https://github.com/boseji/xxtea-iot-crypt/issues/12 and one on stack overflow: arduino - esp32 and php XXTEA strings encryption - Stack Overflow but both of those didn't get me the response I wanted, I didn't even get a response on GitHub.
Is there a way to encrypt and decrypt strings between PHP and esp32?

1 Like

Sorry, Im over 1 year later, but I am on the same path as you right now. I am looking for a way to encrpyt a string of data on my esp32, and decode it on my server using php. I have followe all your post oer stackoverflow, github, and here, I havent found anything reliabale. Ive tested a few methods, but he same key and AES method havent been able to encrypt a simple string like "Hello World" and being able to decrypt it on my server using PHP correctly. Have you solved this issue?