How to use the crypto-js.HmacSHA256 function in crypto-js

To help you get started, we’ve selected a few crypto-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github skyway / skyway-peer-authentication-samples / nodejs / sample.js View on Github external
function calculateAuthToken(peerId, timestamp) {
  // calculate the auth token hash
  const hash = CryptoJS.HmacSHA256(`${timestamp}:${credentialTTL}:${peerId}`, secretKey);

  // convert the hash to a base64 string
  return CryptoJS.enc.Base64.stringify(hash);
}
github WP-API / client-js / vendor / js / oauth-1.0a.js View on Github external
this.hash = function(base_string, key) {
                return CryptoJS.HmacSHA256(base_string, key).toString(CryptoJS.enc.Base64);
            };
            break;
github mateodelnorte / coinbase / lib / index.js View on Github external
function get (url, callback) {
    var nonce = getNonce();
    var message = nonce + url;
    var signature = cryptoJS.HmacSHA256(message, self.apiSecret);
    var reqObject = {
      url: url,
      headers: {
        'ACCESS_KEY': self.apiKey,
        'ACCESS_SIGNATURE': signature,
        'ACCESS_NONCE': nonce
      }
    }

    request.get(reqObject, function (err, res, data) {
      if (err) {
        return callback(err);
      } else {
        try {
          data = JSON.parse(data);
        } catch (err) {
github claudiajs / serverless-chat / src / lib / sigv4url.js View on Github external
const sign = function (key, msg) {
		'use strict';
		const hash = CryptoJS.HmacSHA256(msg, key);
		return hash.toString(CryptoJS.enc.Hex);
	},
	sha256 = function (msg) {
github nknorg / nkn / dashboard / web / helpers / crypto.js View on Github external
export function hmacSHA256(message, secret) {
  secret = secret || message
  return CryptoJS.HmacSHA256(message, secret).toString()
}
github luzzif / binance-api-client / src / BinanceApiClient.ts View on Github external
if (authenticationMethod === AuthenticationMethod.SIGNED) {
            if (isNullOrUndefined(BinanceApiClient.API_SECRET)) {
                throw new AuthenticationError(
                    httpMethod,
                    apiUrl,
                    authenticationMethod
                );
            }
            apiUrl.searchParams.append(
                "timestamp",
                new Date().getTime().toString()
            );
            apiUrl.searchParams.append(
                "signature",
                CryptoJs.HmacSHA256(
                    apiUrl.searchParams.toString(),
                    BinanceApiClient.API_SECRET
                ).toString()
            );
        }
        return headers;
    }
}
github TranceGeniK / bybit-tools / src / plugins / bybitApi.js View on Github external
signData(data) {
          data.api_key = this.account.apiKey;
          data.timestamp = Date.now() - 2000;
          data.recv_window = 25000;
          let dataString = this.objToString(this.sortObject(data));
          data.sign = CryptoJS.HmacSHA256(dataString, this.account.apiSecret).
              toString();
          return this.sortObject(data);
        },
        sortObject(o) {
github aws / aws-iot-device-sdk-js / device / index.js View on Github external
function getSignatureKey(key, dateStamp, regionName, serviceName) {
   var kDate = crypto.HmacSHA256(dateStamp, 'AWS4' + key, {
      asBytes: true
   });
   var kRegion = crypto.HmacSHA256(regionName, kDate, {
      asBytes: true
   });
   var kService = crypto.HmacSHA256(serviceName, kRegion, {
      asBytes: true
   });
   var kSigning = crypto.HmacSHA256('aws4_request', kService, {
      asBytes: true
   });
   return kSigning;
}
github F4b1n0u / my-games / app / services / amazon.js View on Github external
const uri = '/onca/xml'
  const params = {
    AssociateTag: 'fbdevmygames-21',
    AWSAccessKeyId: 'AKIAJ3IDBVUW6HZZFHWQ',
    Keywords: barcode,
    Operation: 'ItemSearch',
    ResponseGroup: 'ItemAttributes',
    SearchIndex: 'VideoGames',
    Service: 'AWSECommerceService',
    Timestamp: now.format('YYYY-MM-DD[T]HH:mm:ss[Z]')
  }

  const canonicalQueryString = qs.stringify(params)
  const stringSoSign = `GET\n${endpoint}\n${uri}\n${canonicalQueryString}`
  
  const hash = crypto.HmacSHA256(stringSoSign, AWS_SECRET_ACCESS_KEY)
  const signature = hash.toString(crypto.enc.Base64)
  
  const signedUrl = `http://${endpoint}${uri}?${canonicalQueryString}&Signature=${encodeURIComponent(signature)}`

  const setting = {
    method: 'GET',
    url: signedUrl,
    responseType: 'text',
  }

  return ajax(setting)
    .map((response) => {
      const xmlResponse = response.response
      const jsonResponse = new X2JS().xml2js(xmlResponse)
      let gameName = _.get(jsonResponse, 'ItemSearchResponse.Items.Item.ItemAttributes.Title', '')
      gameName = gameName.replace(/\([^()]*\)/g, '')
github aws / aws-iot-device-sdk-js / device / index.js View on Github external
function getSignatureKey(key, dateStamp, regionName, serviceName) {
   var kDate = crypto.HmacSHA256(dateStamp, 'AWS4' + key, {
      asBytes: true
   });
   var kRegion = crypto.HmacSHA256(regionName, kDate, {
      asBytes: true
   });
   var kService = crypto.HmacSHA256(serviceName, kRegion, {
      asBytes: true
   });
   var kSigning = crypto.HmacSHA256('aws4_request', kService, {
      asBytes: true
   });
   return kSigning;
}