Guest User

Arduino string encryption WIP

a guest
Mar 6th, 2019
115
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <AESLib.h>
  2. #include <SPI.h>
  3. #include <Adafruit_Sensor.h>
  4. #include "DHT.h"
  5. #include <RH_ASK.h>
  6. #include <Base64.h>
  7.  
  8. #define DHTPIN 2     // what digital pin we're connected to
  9.  
  10. #define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
  11. DHT dht(DHTPIN, DHTTYPE);
  12. RH_ASK driver;
  13.  
  14. uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
  15.  
  16. uint8_t string_key[] = {97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112};
  17. String test_message = "HelloIamamessag";
  18. char data[16];
  19.  
  20. void setup() {
  21.   driver.init();
  22.   dht.begin();
  23.   Serial.begin(9600);
  24. }
  25.  
  26. void loop() {
  27.   // Wait a few seconds between measurements.
  28.   delay(5000);
  29.  
  30.   test_message.toCharArray(data, 16);
  31.   Serial.print("data is:\t");
  32.   Serial.print(data);
  33.  
  34.   aes128_enc_single(string_key, data);
  35.   // Serial.print("\nEncrypted string is:\t");
  36.   // Serial.println(data);  
  37.   int encryptedStringLength = sizeof(data);
  38.   int encodedLength = Base64.encodedLength(encryptedStringLength);
  39.   char encodedString[encodedLength];
  40.   Base64.encode(encodedString, data, encryptedStringLength);
  41.   Serial.print("\nEncoded string is:\t");
  42.   Serial.println(encodedString);
  43. }
RAW Paste Data