How to use the crypto-js.HmacSHA1 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 greizgh / Phashword / src / hasher.js View on Github external
function _hashPassword(tag, key, length, type) {
  let hash = CryptoJS.HmacSHA1(tag, key).toString(CryptoJS.enc.Base64);
  hash = hash.slice(0, -1); // remove trailing '=' to ensure compatibility with Twik

  let sum = 0;
  for (let i = 0; i < hash.length; i++) {
    sum += hash.charCodeAt(i);
  }

  /* Parse password to match the request type */
  if (type === PASSWORD_TYPES.NUMERIC) {
    hash = convertToDigits(hash, sum, length);
  } else {
    /* We force digits, punctuation characters and mixed case */
    // Force digits
    hash = injectCharacter(hash, 0, 4, sum, length, '0', 10);
    if (type == PASSWORD_TYPES.SPECIAL) {
      // Force special chars
github RedFroggy / angular-spring-hmac / src / main / static / src / app / utils / hmac-http-client.ts View on Github external
let date:string = new Date().toISOString();
            let secret:string = securityToken.secret;

            let message = '';
            if (body !== null && body !== '' && (method === 'PUT' || method === 'POST' || method === 'PATCH')) {
               message = method + body + url + date;
            } else {
                message = method + url + date;
            }

            console.log('securityToken', securityToken);

            if (securityToken.isEncoding('HmacSHA256')) {
                options.headers.set(AppUtils.HEADER_X_DIGEST, CryptoJS.HmacSHA256(message, secret).toString());
            } else if (securityToken.isEncoding('HmacSHA1')) {
                options.headers.set(AppUtils.HEADER_X_DIGEST, CryptoJS.HmacSHA1(message, secret).toString());
            } else if (securityToken.isEncoding('HmacMD5')) {
                options.headers.set(AppUtils.HEADER_X_DIGEST, CryptoJS.HmacMD5(message, secret).toString());
            }
            options.headers.set(AppUtils.HEADER_X_ONCE, date);

            console.log('url',url);
            console.log('message',message);
            console.log('secret',secret);
            console.log('hmac message',options.headers.get(AppUtils.HEADER_X_DIGEST));
        }

    }
    setOptions(options?: RequestOptionsArgs):RequestOptionsArgs {
github expo / expo-twitter-login-example / twitter-login-backend / index.js View on Github external
const encodedParameters = percentEncodeParameters(params);
  const upperCaseHTTPMethod = httpMethod.toUpperCase();
  const encodedRequestURL = encodeURIComponent(requestURL);
  const encodedConsumerSecret = encodeURIComponent(consumerSecret);

  const signatureBaseString = upperCaseHTTPMethod +
    '&' + encodedRequestURL +
    '&' + encodeURIComponent(encodedParameters);

  let signingKey;
  if (tokenSecret !== undefined) {
    signingKey = encodedRequestURL + '&' + encodeURIComponent(tokenSecret);
  } else {
    signingKey = encodedConsumerSecret + '&';
  }
  const signature = Crypto.HmacSHA1(signatureBaseString, signingKey);
  const encodedSignature = Crypto.enc.Base64.stringify(signature);
  return encodedSignature;
}
github aliyun / alibabacloud-iot-device-sdk / src / utils.js View on Github external
function hmacSign(type, secret, content) {
  return cryptojs.HmacSHA1(content,secret).toString();
}
github qiniudemo / react-native-sdk / core / auth.js View on Github external
exports.hmacSha1 = function(encodedFlags, secretKey) {
  var encoded = CryptoJS.HmacSHA1(encodedFlags, secretKey).toString(CryptoJS.enc.Base64);;
  return encoded;
}
github FineUploader / server-examples / nodejs / s3 / s3handler.js View on Github external
function getV2SignatureKey(key, stringToSign) {
    var words = CryptoJS.HmacSHA1(stringToSign, key);
    return CryptoJS.enc.Base64.stringify(words);
}
github postmanlabs / newman / src / utilities / oauth.js View on Github external
function getSignature(baseString) {
            b64pad = '=';
            var signature = CryptoJS.HmacSHA1(baseString, this.key).toString(CryptoJS.enc.Base64);
            return signature;
        }
    ));