Thanks for sharing this fine example! It really helped me in decoding the mote's payload in my application.
For a first proof of concept we want to receive mote data on our server, decrypt it, think of some response, encrypt it, and finally send this response back to the gateway.
The first part works fine with your Crypto class, but when I get to encrypting it becomes hard for me to actually pull it off. I've added this code snippet as an example, it uses the Semtech default key:
public static void testDecoder() throws Exception {
byte [] key = new byte [] {0x2B, 0x7E, 0x15, 0x16, 0x28, (byte) 0xAE, (byte) 0xD2, (byte) 0xA6, (byte) 0xAB, (byte) 0xF7, 0x15, (byte) 0x88, 0x09, (byte) 0xCF, 0x4F, 0x3C};
byte [] iv = new byte [] {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
String message = "thisisverysecret";
byte[] encrypted = Crypto.encryptAES(message.getBytes(), key, iv);
String encoded = Base64.getEncoder().encodeToString(encrypted);
String decrypted = Crypto.decrypt(encoded, key, iv);
System.out.println(decrypted);
}
I would expect that the snippet above would print "thisisverysecret", but I cannot get it to work the way I expect it to..
Could you maybe provide me with a code snippet that shows me how to correctly use your Crypto class to encrypt and decrypt again?
Would be very much appreciated!