Happy Holidays! I am trying to gain access to the charger for an electric vehicle. I found only one reference and it is in Python. It also indicates that the charger uses SHA256 encryption. I am not familiar with either.
After connecting, the charger sends a websocket message with a JSON payload of
{"type":"authRequired","token1":"hrqvxW9Qk5cnYz9AQIHJ7K4uAJQGaQ1b","token2":"GN6iaGAk57F0Rs0iRsAeoYOUm7SS32VR"}
Of course, the tokens change each time. I need to send a response which is calculated in Python as:
My questions:
1: Am I correct that lines 1-3 simply generate 32 random bytes?
2: Line 5 simply ensures that token1 is ASCII (which it already is in my case)?
3: Am I correct that lines 4-6 generates a SHA256 hash of token1 + the hashed password?
4: What does .hexdigest() do? My first assumption was that it was a method of the sha256 library, but research suggests digest() has something to do with concatenation and hexdigest() returns the result of digest() as a hex string?
5: Is customJWT by Ant2000 an appropriate sha256 encoding/decoding library for this?
I'm lost and would greatly appreciate any assistance anyone may be able to provide. Thank you!
calls two methods that you'd have to also dig up and "translate", which methods might use others, or more features of Python that have no direct equivalents in plan C++ coding.
Outside the context of a full Python solution moving it to C++ is not going to be a matter of answering a few questions about one small part.
Thank you for your comments thus far. Perhaps I didn't make myself perfectly clear.
I have been a professional programmer since 1980 and used every language from COBOL, C in all its variations, Java, more dialects of BASIC, DBase and SQL than I can remember, ABAP, and lots of languages I can't even remember the names of anymore. I never used Python, am now retired and don't really want to learn a new language.
I need to know what those Python expressions do and then I will implement them myself for my project.
I am not running this on an ATMega328 8bit 16MHz MCU, but an ESP32S3, 32bit at 240MHz.
Espressif says that MCU even has a hardware accellerator built-in for SHA256 but I have just started researching that.