Skip to content

Instantly share code, notes, and snippets.

@kakopappa
Last active October 3, 2020 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakopappa/f2a97c449199217e20cc7af688611d80 to your computer and use it in GitHub Desktop.
Save kakopappa/f2a97c449199217e20cc7af688611d80 to your computer and use it in GitHub Desktop.
How to Encrypt in Flutter and Decrypt in ESP8266
Encrypt in Flutter
String encryptDecrypt(String input) {
var key = ['KCQ']; //Can be any chars, and any size array
var output = [];
for(var i = 0; i < input.length; i++) {
var charCode = input.codeUnitAt(i) ^ key[i % key.length].codeUnitAt(0);
output.add(new String.fromCharCode(charCode));
}
return output.join("");
}
Decrypt in ESP8266
String request = "";
char * key = "KCQ";
char *p = const_cast<char*>(request.c_str());
char *xor(char *string, const char *key)
{
char *s = string;
size_t length = strlen(key), i = 0;
while (*s) {
*s++ ^= key[i++ % length];
}
return string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment