0

I am trying to create a string message and then encrypt it via AES but the example only accepts byte array as input. How can I convert fullmessage string to message byte array to encrypt it? Checked similar questions but couldn't resolve the problem.

void loop () 
{
  dt = clock.getDateTime();
  String dash = "-";
  String comma = ",";
  String time = dt.year + dash + dt.month + dash + dt.day + dash + dt.hour + dash + dt.minute + dash + dt.second;
  String status = "OK";
  String fullmessage = time + comma + status;
  byte message[]= "anything";
  plainLength = sizeof(message)-1; 
  padedLength = plainLength + N_BLOCK - plainLength % N_BLOCK;
  prekey(256,message);  
  delay(2000);
}
  • 1
    do you get an error? – jsotola Jan 2 at 23:21
  • "cannot convert ‘String’ to ‘byte {aka unsigned char}’ in assignment" I get this when trying to put fullmessage directly as message. Now I was trying to use message[i] = fullmessage[i] in a for loop, seems like it worked. – heathcliff Jan 2 at 23:25
  • 2
    strcpy(message, fullMessage.c_str()); allocate message as char message[MESSAGE_SIZE]; tutorialspoint.com/c_standard_library/string_h.htm – Juraj Jan 3 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.