We are developing an online course website.
Courses have audio and text (no video).
Audio files are stored on Amazon S3 and delivered via AWS CloudFront.
Every time a user wants to play a course audio file,
website (server side) sends a request to CloudFront to get the audio file.
Each request also includes a signature and a random number.
We use PHP hash_hmac to generate the signature as follows:
$signature = hash_hmac('sha256', $random_number, $secret, true);
Both sides (website and CloudFront function) have the secret key hard-coded.
Once CloudFront receives the request,
a "CloudFront Function" (new AWS feature) is validating the token.
CloudFront Function can only use JavaScript (not NodeJS nor Python).
https://aws.amazon.com/blogs/aws/introducing-cloudfront-functions-run-your-code-at-the-edge-with-low-latency-at-any-scale/
We want CloudFront function to simply run hash_hmac() using JavaScript
and then compare the signatures but we could not find an equivalent JS function.
We checked extensively on StackOverflow but could not find an equivalent JS function.
Our findings:
Google`s Crypto-JS library is deprecated.
NodeJS Crypto module cannot be used since we use plain JavaScript.
Can someone PLEASE share a link or a code snippet on how to run hash_hmac on JavaScript?