ESP32 + PHP string encryption
Posted: Thu Sep 20, 2018 4:58 pm
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: https://github.com/xxtea/xxtea-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:
My PHP code looks like this:
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: https://stackoverflow.com/questions/523 ... encryption 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?
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: https://github.com/xxtea/xxtea-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:
Code: Select all
#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);
}
Code: Select all
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 have opened two issues, one on GitHub: https://github.com/boseji/xxtea-iot-crypt/issues/12 and one on stack overflow: https://stackoverflow.com/questions/523 ... encryption 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?