Crypto Tools: HMAC

This flow implements capabilities for creating Hash-Based Message Authentication Codes with user provided data using Secure Hash Algorithm

[{"id":"422a2f30f429bc31","type":"subflow","name":"HMAC","info":"This subflow implements capabilities for creating **Hash-Based Message Authentication Codes** with user provided data using *Secure Hash Algorithm*.The subflow supports the following versions of **SHA**:\n\n- SHA1 = \"1\"\n- SHA224 = \"224\"\n- SHA256 = \"256\"\n- SHA384 = \"384\"\n- SHA512 = \"512\"\n- SHA3 = \"3\"\n\n## *Hashing*\n### Inputs\n>\n> **payload.*version***: SHA version to use. (Optional)\n>\n> **payload.*key***: Key to use in the HMAC.\n>\n> **payload.*data***: Data to Hash.\n>\n\n### Outputs\n>\n> **payload.*algo***: Algorithm used for Hashing.\n>\n> **payload.*hash***: Hash of provided data.\n>\n","category":"CryptoRed","in":[{"x":60,"y":80,"wires":[{"id":"54d1fe1eeb773754"}]}],"out":[{"x":610,"y":80,"wires":[{"id":"54d1fe1eeb773754","port":0}]}],"env":[{"name":"version","type":"str","value":"1","ui":{"icon":"font-awesome/fa-gear","label":{"en-US":"Version"},"type":"select","opts":{"opts":[{"l":{"en-US":"SHA1"},"v":"1"},{"l":{"en-US":"SHA224"},"v":"224"},{"l":{"en-US":"SHA256"},"v":"256"},{"l":{"en-US":"SHA384"},"v":"384"},{"l":{"en-US":"SHA512"},"v":"512"},{"l":{"en-US":"SHA3"},"v":"3"}]}}},{"name":"key","type":"str","value":"","ui":{"icon":"font-awesome/fa-key","label":{"en-US":"Key"},"type":"input","opts":{"types":["str"]}}}],"meta":{"module":"node-red-contrib-crypto-tools-hmac","version":"0.0.1","author":"Thodoris Ioannidis <[email protected]>","desc":"Hash-Based Message Authentication Code functionalities","keywords":"SHA, HMAC, Hashing","license":"Apache-2.0"},"color":"#3FADB5","inputLabels":["message"],"outputLabels":["hmac"],"icon":"font-awesome/fa-key"},{"id":"54d1fe1eeb773754","type":"function","z":"422a2f30f429bc31","name":"Hash-based Message Authentication Code","func":"function HMAC1(data,key){\n    let hmac = cryptoJs.algo.HMAC.create(cryptoJs.algo.SHA1,key)\n    hmac.update(JSON.stringify(data));\n    return hmac.finalize().toString();\n}\nfunction HMAC224(data,key){\n    let hmac = cryptoJs.algo.HMAC.create(cryptoJs.algo.SHA224,key)\n    hmac.update(JSON.stringify(data));\n    return hmac.finalize().toString();\n}\nfunction HMAC256(data,key){\n    let hmac = cryptoJs.algo.HMAC.create(cryptoJs.algo.SHA256,key)\n    hmac.update(JSON.stringify(data));\n    return hmac.finalize().toString();\n}\nfunction HMAC384(data,key){\n    let hmac = cryptoJs.algo.HMAC.create(cryptoJs.algo.SHA384,key)\n    hmac.update(JSON.stringify(data));\n    return hmac.finalize().toString();\n}\nfunction HMAC512(data,key){\n    let hmac = cryptoJs.algo.HMAC.create(cryptoJs.algo.SHA512,key)\n    hmac.update(JSON.stringify(data));\n    return hmac.finalize().toString();\n}\nfunction HMAC3(data,key){\n    let hmac = cryptoJs.algo.HMAC.create(cryptoJs.algo.SHA3,key)\n    hmac.update(JSON.stringify(data));\n    return hmac.finalize().toString();\n}\n\ndata = msg.payload\nlet hmac, algo, version = data.version || env.get('version')\nswitch(version){\n    case \"1\":\n        algo = \"SHA1\"\n        hmac = HMAC1(data.data, data.key|| env.get('key'))\n        break;\n    case \"224\":\n        algo = \"SHA224\"\n        hmac = HMAC224(data.data, data.key|| env.get('key'))\n        break;\n    case \"256\":\n        algo = \"SHA256\"\n        hmac = HMAC256(data.data, data.key|| env.get('key'))\n        break;\n    case \"384\":\n        algo = \"SHA384\"\n        hmac = HMAC384(data.data, data.key|| env.get('key'))\n        break;\n    case \"512\":\n        algo = \"SHA512\"\n        hmac = HMAC512(data.data, data.key|| env.get('key'))\n        break;\n    case \"3\":\n        algo = \"SHA3\"\n        hmac = HMAC3(data.data, data.key|| env.get('key'))\n        break;\n}\n\nmsg.payload = {\n    algo: algo,\n    hash: hmac\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"cryptoJs","module":"crypto-js"}],"x":310,"y":80,"wires":[[]]}]

Flow Info

Created 2 years, 3 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • function (x1)
Other
  • subflow (x1)

Tags

  • hmac
  • hashing
  • integrity
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option