How to create base64 hashes using HMAC SHA256 in JavaScript

1 Answer

0 votes
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/hmac-sha256.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/enc-base64.min.js"></script>
</head>
const secretkey = "45fd2ds908hjcx";
const message = "javascript programming"

let hash = CryptoJS.HmacSHA256(message, secretkey);
var hashBase64 = CryptoJS.enc.Base64.stringify(hash);

console.log(hashBase64)



/*
run:

mIflD34A/M9cm7qS7Q5hn5+08d0rGT0cNxuy84lqp84=

*/

 



answered Aug 8, 2020 by avibootz
...