Skip to content

XXTEA Encryption and Decryption Library for Arduino

Notifications You must be signed in to change notification settings

edgarreis/xxtea-iot-crypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xxtea-iot-crypt library for Arduino

Encryption Library for IoT devices

This library implements both RAW data encryption as well as string encryption and decryption for XXTEA.

Example - RAW Encryption / Decryption

#include <xxtea-iot-crypt.h>

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

void loop() {
  Serial.println();
  uint8_t keybuf[] = "Hello Password";
  uint8_t plaintext[] = "Hi There we can work with this";
  uint8_t buffer[200];
  int32_t len = 200, i;
  Serial.printf(" Password : %s\n", keybuf);
  // Setup the Key - Once
  if(xxtea_setup(keybuf, strlen((char *)keybuf)) != XXTEA_STATUS_SUCCESS)
  {
    Serial.println(" Assignment Failed!");
    return;
  }
  Serial.printf(" Plain Text: %s\n", plaintext);
  // Perform Encryption on the Data
  len = 200;  // - Initialize the Maximum buffer length
  if(xxtea_encrypt(plaintext, strlen((char*)plaintext), buffer, &len) !=
    XXTEA_STATUS_SUCCESS)
  {
    Serial.println(" Encryption Failed!");
    return;
  }
  else
  {
    Serial.print(" Encrypted Data: ");
    for(i = 0;i<len;i++)
      Serial.printf("0x%02X ", buffer[i]);
    Serial.println();
  }
  // Perform Decryption
  if(xxtea_decrypt(buffer, len) != XXTEA_STATUS_SUCCESS)
  {
    Serial.println(" Decryption Failed!");
    return;
  }
  else
  {
    Serial.printf(" Decrypted Data: %s\n", buffer);
  }
  delay(1000);
}

Example - Easy String based Encryption / Decryption

#include <xxtea-iot-crypt.h>

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

void loop() {
  Serial.println();

  String keybuf = F("Hello Password");
  Serial.print(F(" Password : "));
  Serial.println(keybuf);

  // Setup the Key - Once
  if(!xxtea.setKey(keybuf))
  {
    Serial.println(" Assignment Failed!");
    return;
  }

  String plaintext = F("Hi There we can work with this");
  Serial.print(" Plain Text: ");
  Serial.println(plaintext);

  // Perform Encryption on the Data
  String result = xxtea.encrypt(plaintext);
  if(result == F("-FAIL-"))
  {
    Serial.println(" Encryption Failed!");
    return;
  }
  else
  {
    Serial.print(F(" Encrypted Data: "));
    Serial.println(result);
  }

  // Perform Decryption
  String result1 = xxtea.decrypt(result);
  if(result1 == F("-FAIL-"))
  {
    Serial.println(" Decryption Failed!");
    return;
  }
  else
  {
    Serial.print(F(" Decrypted Data: "));
    Serial.println(result1);
  }
  delay(1000);
}

Dependencies

Thread Safe: No
Extendable: Yes

For more information about this library please visit us at http://github.com/boseji/xxtea-iot-crypt

License

Released Under creative commons license 3.0: Attribution-ShareAlike CC BY-SA

About

XXTEA Encryption and Decryption Library for Arduino

Resources

Stars

Watchers

Forks

Packages

No packages published