suculent / thinx-aes-lib

AES wrapper for ESP8266/ESP32/Arduino/nRF5x
Other
118 stars 37 forks source link

Encrypted Key changed after next attempt #47

Closed albertlt closed 3 years ago

albertlt commented 3 years ago

Hello. I encrypted text: "4A31D880" with aes key: { 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61 }. and IV: {0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30}. paddingMode::Null.

First encrypt: ZIANFxqhMhVqryJ/QjFW7A== Second encrypt: Jl+J50IW7L6NniwCw3eZFg== Third encrypt: tPhroIswnTtFeUd5IyeX/g==

Key and IV never change. If I restart the esp32, the encryption will goes back to first one. The first one can be decrypted correctly, the rest cant. Why is that?

albertlt commented 3 years ago

Ok, so I put the IV as class variable. It seems that the lib automatically change the key after each encrypt. If I put the IV inside the encrypt function, it doesn't change anymore. Is that expected behaviour?

suculent commented 3 years ago

The IV changes on each encrypted block. That’s why examples explicitly keep iv aside and use always fresh copy. Otherwise it’s usual to send the IV to the other side as part of encrypted data.

Hope this helps.

    1. 2021 v 12:53, albertlt @.***>:

 Ok, so I put the IV as class variable. It seems that the lib automatically change the key after each encrypt. If I put the IV inside the encrypt function, it doesn't change anymore. Is that expected behaviour?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

albertlt commented 3 years ago

nvm, error logic in my app. thank you for the great lib :)