UEC++ From Basics to Advanced | M27-007: HMAC-SHA256 Encryption in Unreal Engine

This lesson implements HMAC-SHA256 encryption using OpenSSL in UE5. The instructor writes a C++ encryption function that takes binary data and an API secret key, returning a 32-byte HMAC digest. The implementation calls OpenSSL's HMAC function directly, with careful handling of input pointers, data lengths, and output buffers. The lesson also demonstrates using FBase64Encode to convert the binary digest to a Base64 string for HTTP transmission. The instructor explains why directly using OpenSSL is preferable to Unreal's platform encryption module, which varies across engine versions and platforms. The lesson also covers testing encryption output with online HMAC tools and Python scripts, emphasizing the importance of verifying encryption correctness before debugging API integration issues. This encryption function is critical for iFLYTEK API authentication. Students learn the complete HMAC-SHA256 workflow: constructing the signature string from host, date, and request line parameters, encrypting with the API secret, Base64-encoding the result, and including it in the Authorization header of every API request.