Something went wrong. Try again.
A fork of https://github.com/crosspoint-reader/crosspoint-reader
Something went wrong. Try again.
1.5 kB · 39 lines
C
12345678910111213141516171819202122232425262728293031323334353637383940#pragma once
#include <Arduino.h>
#include <cstddef>#include <cstdint>#include <string>
/** * Credential obfuscation utilities using the ESP32's unique hardware MAC address. * * XOR-based obfuscation with the 6-byte eFuse MAC as key. Not cryptographically * secure, but prevents casual reading of credentials on the SD card and ties * obfuscated data to the specific device (cannot be decoded on another chip or PC). * */namespace obfuscation {
// XOR obfuscate/deobfuscate in-place using hardware MAC key (symmetric operation)void xorTransform(std::string& data);
// Legacy overload for binary migration (uses the old per-store hardcoded keys)void xorTransform(std::string& data, const uint8_t* key, size_t keyLen);
// Obfuscate a plaintext string: XOR with hardware key, then base64-encode for JSON storageString obfuscateToBase64(const std::string& plaintext);
// Decode base64 and de-obfuscate back to plaintext.// Returns empty string on invalid base64 input; sets *ok to false if decode fails.std::string deobfuscateFromBase64(const char* encoded, bool* ok = nullptr);
// Bounded variant. Rejects decoded output larger than maxDecodedLength before// allocating its result buffer and reports that case through tooLong.std::string deobfuscateFromBase64(const char* encoded, size_t maxDecodedLength, bool* ok, bool* tooLong);
// Self-test: verifies round-trip obfuscation with hardware key. Logs PASS/FAIL.void selfTest();
} // namespace obfuscation