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>
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.
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.