AES encryption from Arduino to Android


i'm little confused on configuration should use on 2 libraries using programming arduino , android. want able to:
1. create random string in arduino
2. pass android encrypt aes , shared secret key
3. pass arduino decrypt aes , shared secret key
4. verify original random string matches decrypted string

i using this arduino library , this android library

my arduino code set test encrypting decrypting:
code: [select]
#include <aes.h>

aes aes ;

#define keylength 32
char passstring[] = "this hard believe true";
byte key[keylength];

char message[] = "ncrypted message";

byte plain[n_block];
byte cipher [n_block] ;
byte decrypted [n_block] ;

void setup() {
  serial.begin(9600);
  serial.println(f("starting aes test"));
 
  // pass key byte array
  (int = 0; < keylength; i++) {
    key[i] = passstring[i];
  }
 
  if (aes.set_key (key, keylength) !=0){
    serial.println(f("failed set key"));
  }
}

void loop() {
  // show original message
  serial.print(f("un-encrypted message: "));
  serial.println(message);
  serial.println(f("un-encrypted binary: "));
  (int = 0; < n_block; i++) {
    plain[i] = message[i];
    cipher[i] = 0;
    decrypted[i] = 0;
    serial.print(plain[i]);
    serial.print(f(" "));
  }
  serial.println(f(""));
 
  // show encrypted message
  if (aes.encrypt(plain, cipher) == 0) {
    serial.println(f("encrypted: "));
    (int = 0; < n_block; i++) {
      serial.print(cipher[i]);
      serial.print(f(" "));
    }
    serial.println(f(""));
  } else {
    serial.println(f("failed encrypt"));
  }
 
  // show decrypted message
  if (aes.decrypt(cipher, decrypted) == 0) {
    serial.println(f("decrypted binary: "));
    (int = 0; < n_block; i++) {
      serial.print(decrypted[i]);
      serial.print(f(" "));
    }
    serial.println(f(""));
    serial.println(f("decrypted char: "));
    (int = 0; < n_block; i++) {
      serial.print(char(decrypted[i]));
    }
    serial.println(f(""));
   
  } else {
    serial.println(f("failed decrypt"));
  }
 
 
  serial.println(f("aes test complete"));
  delay(100000);
 
}


my android program verbatim link above.

i can both of them encrypt , decrypt own messages, set ups seem different , haven't been able encrypt each others. android code seems have quite bit more involved creating keys , salts. both libraries pretty versatile , i'm not sure how make them encrypt same way.

i seem missing basics concepts, after researching i've done on encryption i've realized 1 of confusing , difficult parts of project! push in right direction appreciated.

i don't know either of libraries you've mentioned take realise there should 2 keys.  1 encrypting, other decrypting. 

you can't use same key decrypt used encrypt. 


Arduino Forum > Using Arduino > Programming Questions > AES encryption from Arduino to Android


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code