Skip to content

Instantly share code, notes, and snippets.

@bazo
Created November 30, 2015 10:06
Show Gist options
  • Save bazo/032e6e087f4df713240c to your computer and use it in GitHub Desktop.
Save bazo/032e6e087f4df713240c to your computer and use it in GitHub Desktop.
ZbgaeK
let data = {
type: 'invoice',
author: 'martin',
timestamp: timestamp,
apiKey: apiKey
};
document.write(JSON.stringify(data));
document.write('sorting...');
let sortedObject = {};
let keys = Object.keys(data);
keys.sort();
for (let i = 0, size = keys.length; i < size; i++) {
const key = keys[i];
const value = object[key];
sortedObject[key] = value;
}
document.write(JSON.stringify(sortedObject));
const hash = CryptoJS.HmacSHA512(data, "apiKey");
const signature = hash.toString(CryptoJS.enc.Base64);
document.write(signature);
<script src="https://raw.githubusercontent.com/brix/crypto-js/develop/src/core.js"></script>
<script src="https://raw.githubusercontent.com/brix/crypto-js/develop/src/sha512.js"></script>
<script src="https://github.com/brix/crypto-js/blob/develop/src/hmac.js"></script>
<script src="https://github.com/brix/crypto-js/blob/develop/src/enc-base64.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment