Skip to main content
Added further suggestion for debugging
Source Link
Mark Smith
  • 2.2k
  • 1
  • 10
  • 14

By inspection only:

You are using an Initialization Vector and CBC mode in your Python code, but no IV and single block encryption in your Arduino code.

I think if you use MODE_ECB in your Python it will ignore the IV and match the Arduino code.

From a look at the AESLib github it appears your key should be exactly 16 bytes - yours is 32. I haven't looked at the code to see whether it will just ignore the rest, but the Python code definitely won't, so you should probably do what it says and use 16, and adjust your Python code to match.

Since the above wasn't enough to get it working, I would suggest divide-and-conquer: Use an online AES-128 encyrptor/decryptor such as aesencryption.net or encode-decode.com or infoencrypt.com to validate and cross-check your Arduino encryption and Python decryption functions. With a bit of luck you can at least fix them one-by-one, against a known-good reference. Perhaps with a bit of fiddling you may be able to work out where it's going wrong.

I presume the humidity value may not change much, and I have a feeling that sending several messages with the same start can substantially weaken the encryption but I'm no crypto expert and perhaps it's still adequate for your purposes.

By inspection only:

You are using an Initialization Vector and CBC mode in your Python code, but no IV and single block encryption in your Arduino code.

I think if you use MODE_ECB in your Python it will ignore the IV and match the Arduino code.

From a look at the AESLib github it appears your key should be exactly 16 bytes - yours is 32. I haven't looked at the code to see whether it will just ignore the rest, but the Python code definitely won't, so you should probably do what it says and use 16, and adjust your Python code to match.

I presume the humidity value may not change much, and I have a feeling that sending several messages with the same start can substantially weaken the encryption but I'm no crypto expert and perhaps it's still adequate for your purposes.

By inspection only:

You are using an Initialization Vector and CBC mode in your Python code, but no IV and single block encryption in your Arduino code.

I think if you use MODE_ECB in your Python it will ignore the IV and match the Arduino code.

From a look at the AESLib github it appears your key should be exactly 16 bytes - yours is 32. I haven't looked at the code to see whether it will just ignore the rest, but the Python code definitely won't, so you should probably do what it says and use 16, and adjust your Python code to match.

Since the above wasn't enough to get it working, I would suggest divide-and-conquer: Use an online AES-128 encyrptor/decryptor such as aesencryption.net or encode-decode.com or infoencrypt.com to validate and cross-check your Arduino encryption and Python decryption functions. With a bit of luck you can at least fix them one-by-one, against a known-good reference. Perhaps with a bit of fiddling you may be able to work out where it's going wrong.

I presume the humidity value may not change much, and I have a feeling that sending several messages with the same start can substantially weaken the encryption but I'm no crypto expert and perhaps it's still adequate for your purposes.

Source Link
Mark Smith
  • 2.2k
  • 1
  • 10
  • 14

By inspection only:

You are using an Initialization Vector and CBC mode in your Python code, but no IV and single block encryption in your Arduino code.

I think if you use MODE_ECB in your Python it will ignore the IV and match the Arduino code.

From a look at the AESLib github it appears your key should be exactly 16 bytes - yours is 32. I haven't looked at the code to see whether it will just ignore the rest, but the Python code definitely won't, so you should probably do what it says and use 16, and adjust your Python code to match.

I presume the humidity value may not change much, and I have a feeling that sending several messages with the same start can substantially weaken the encryption but I'm no crypto expert and perhaps it's still adequate for your purposes.