Created
February 18, 2019 13:05
-
-
Save kakopappa/553b2da6433eb61e4dbe9556123e5b62 to your computer and use it in GitHub Desktop.
Hmac sha256 url parameter signature validate using dart and nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dart | |
void _incrementCounter() { | |
String secret = "762c4144-1630-4fab-9161-0fef8b18d316"; | |
List<int> key = utf8.encode(secret); | |
String message = "clientId=android-app&type=action&ts=1550493108338&actions=%5B%7B%22name%22%3A%22setOn%22%2C%22parameters%22%3A%7B%7D%7D%5D"; | |
List<int> messageBytes = utf8.encode(message); | |
Hmac hmac = new Hmac(sha256, key); | |
Digest digest = hmac.convert(messageBytes); | |
String base64Mac = base64.encode(digest.bytes); | |
print("base64Mac: " + base64Mac); | |
} | |
// Nodejs | |
let query = "clientId=android-app&type=action&ts=1550493108338&actions=%5B%7B%22name%22%3A%22setOn%22%2C%22parameters%22%3A%7B%7D%7D%5D"; | |
const crypto = require("crypto"); | |
const key = Buffer.from("762c4144-1630-4fab-9161-0fef8b18d316", 'utf8'); | |
console.log("key:" + key.toString('utf8')); | |
let computedSignature = crypto.createHmac("sha256", key).update(query, 'utf8').digest('base64'); | |
console.log(computedSignature); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment