AES Encrypted communication with PC

Hello,
I am trying to develop a interface where data will be encrypted in the Arduino side by AES and then send over to computer. There will be xbee in the com port. The PC side will get the encrypted data and decrypt by using AES. I can encrypt data in the Arduino Side. The program is below. However in the PC side I am having problem to decrytp. I am using java to decrypt. For my PC side I am not geting any suitable AES porgram which depends on fixed key. So i can use the same key as arduino.

Any suggestion or any AES java program?
#include <AESLib.h>

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

void loop() {

uint8_t key = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
char data = “0123456789012345”; //16 chars == 16 bytes
aes128_enc_single(key, data);
Serial.print(“encrypted:”);
for (int i=0;i<16;i++)
Serial.println(data*,DEC);*

delay(500);

}

faisaliut:
I am using java to decrypt. For my PC side I am not geting any suitable AES porgram which depends on fixed key. So i can use the same key as arduino.

Any suggestion or any AES java program?

As of JDK1.5 Java has AES built in through the JCE (Java Cryptographic Extension). To get a match you will need to specify "AES/ECB/NoPadding" when constructing the Cipher object.

You should note that in it's raw form aes128_enc_single() in effect uses ECB block mode which is considered insecure since it permits forgery of ciphertext by splicing. To be secure you need to add code to use one of the feedback block modes such CBC and then you will need to modify the Java to use the same block mode.

Also, if you are not encrypting a multiple of 16 bytes you will need to provide padding on the encryption side and to remove the padding on the decryption side. Java has PKCS5Padding as standard so it might be easiest if you just mimic this in your C/C++ code.

Thanks. I got your point. However I am finding difficulty with the Key issue. In the arduino side its fixed key. However in the java side they use key generator to generate a secret key. So any idea how to resolve that.

faisaliut:
However I am finding difficulty with the Key issue. In the arduino side its fixed key. However in the java side they use key generator to generate a secret key. So any idea how to resolve that.

Very easy -

     byte[] keyBytes = ... // The bytes of your key
     SecretKey key = new SecretKeySpec(keyBytes, "AES");

P.S. To allow 16 byte key you will need to install the Unlimited Strength files in your JRE. Check the Oracle JDK download page.

uint8_t key = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; as this one fixed no salt like whatever you add

SecretKey key = new SecretKeySpec(key, "AES"); So in the pc side different secret key will generate other than key used in Arduino.

Any way that I will use the same {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} this key in pc side?

I'm not sure I understand "So in the pc side different secret key will generate other than key used in Arduino." ! You must have the same key bytes in both the PC and the Arduino; that is the nature of symmetric encryption.

Note - you cannot have the key bytes reference being named 'key' and the SecretKey reference being named 'key' - it will not compile.

Thanks. I got the point. As I am using build in library in arduino. It have different structure.