How to use jssha - 10 common examples

To help you get started, we’ve selected a few jssha 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 FlashAirDevelopers / FlashAirFileManager / src / main / auth.js View on Github external
_makeCodeChallenge(codeVrifier) {
    // calculate SHA-256 hash
    const hashEncoder = new jsSHA('SHA-256', 'TEXT');
    hashEncoder.update(codeVrifier);
    // Base64 encoding and Remove any trailing '='
    let codeChallenge = hashEncoder.getHash('B64').split('=')[0];
    // Replace enable url charactor for Base64url
    codeChallenge = codeChallenge.replace(/\+/g, '-');
    codeChallenge = codeChallenge.replace(/\//g, '_');
    return codeChallenge;
  }
}
github yi-ge / electron-distribution / src / routes / webhooks.js View on Github external
async handler (request) {
      try {
        const shaObj = new JsSHA('SHA-1', 'TEXT')
        shaObj.setHMACKey(SYSTEM.TOKEN, 'TEXT')
        shaObj.update(JSON.stringify(request.payload))
        const hash = shaObj.getHMAC('HEX')
        if (request.headers && request.headers['x-hub-signature'] === 'sha1=' + hash) {
          const updateCodeRes = await gitCodeUpdate(SYSTEM.BUILD_TYPE)
          if (updateCodeRes) {
            const packageJson = JSON.parse(fs.readFileSync(path.join(sourcePath, 'package.json'), 'utf-8'))

            if (packageJson && packageJson.name && packageJson.version) {
              const name = packageJson.name
              const version = packageJson.version
              if (SYSTEM.BUILD_TYPE.includes('mac')) {
                macBuild(name, version) // async
                await sleep(500)
              }
github wKovacs64 / hibp / src / pwnedPassword.ts View on Github external
const pwnedPassword = (
  password: string,
  options: { baseUrl?: string; userAgent?: string } = {},
): Promise => {
  const sha1 = new JSSHA('SHA-1', 'TEXT');
  sha1.update(password);
  const hash = sha1.getHash('HEX', { outputUpper: true });
  const prefix = hash.slice(0, 5);
  const suffix = hash.slice(5);

  return (
    pwnedPasswordRange(prefix, options)
      // filter to matching suffix
      .then(arr => arr.filter(item => item.suffix === suffix))
      // return count if match, 0 if not
      .then(arr => (arr[0] ? arr[0].count : 0))
  );
};
github kegesch / passman-ios / src / lib / TOTP.ts View on Github external
public static getOTP(secret): string {
		try {

			const epoch = Math.round(new Date().getTime() / 1000.0);
			const time = this.leftpad(this.dec2hex(Math.floor(epoch / 30)), 16, '0');

			const shaObj = new JsSHA('SHA-1', 'HEX');
			shaObj.setHMACKey(this.base32tohex(secret), 'HEX');
			shaObj.update(time);

			const hmac = shaObj.getHMAC('HEX');

			const offset = this.hex2dec(hmac.substring(hmac.length - 1));

			let otp = (TOTP.hex2dec(hmac.substr(offset * 2, 8)) & this.hex2dec('7fffffff')) + '';
			otp = (otp).substr(otp.length - 6, 6);

			return otp;

		} catch (err) {
			throw new Error('One-Time-Password could not be calcualted: ' + err);
		}
	}
github Phyks / ampache_react / app / utils / ampache.js View on Github external
export function buildHMAC(password) {
    const time = Math.floor(Date.now() / 1000);

    let shaObj = new jsSHA("SHA-256", "TEXT");
    shaObj.update(password);
    const key = shaObj.getHash("HEX");

    shaObj = new jsSHA("SHA-256", "TEXT");
    shaObj.update(time + key);

    return {
        time: time,
        passphrase: shaObj.getHash("HEX"),
    };
}
github TronLink / tronlink-extension / app / lib / utils.js View on Github external
sha256(string) {
        const shaObj = new Sha('SHA-256', 'HEX');
        shaObj.update(string);
        return shaObj.getHash('HEX');
    },
github Phyks / ampache_react / app / utils / ampache.js View on Github external
export function buildHMAC(password) {
    const time = Math.floor(Date.now() / 1000);

    let shaObj = new jsSHA("SHA-256", "TEXT");
    shaObj.update(password);
    const key = shaObj.getHash("HEX");

    shaObj = new jsSHA("SHA-256", "TEXT");
    shaObj.update(time + key);

    return {
        time: time,
        passphrase: shaObj.getHash("HEX"),
    };
}
github orionx-dev / orionx-sdk-js / src / helpers / callOrionx / generateSignature.js View on Github external
export default ({body, timestamp, secretKey}) => {
  const shaObj = new JSSHA('SHA-512', 'TEXT')
  shaObj.setHMACKey(secretKey, 'TEXT')
  shaObj.update(timestamp + body)
  return shaObj.getHMAC('HEX')
}
github alphapoint / coinslot / src / utils / cryptoUtils.js View on Github external
sha256(hexString) {
    const sha = new SHA('SHA-256', 'HEX');
    sha.update(hexString);

    return sha.getHash('HEX');
  },
};
github TronLink / tronlink-extension / app / pageHook / lib / Utils.js View on Github external
sha256(string) {
        const shaObj = new Sha('SHA-256', 'HEX');
        shaObj.update(string);
        return shaObj.getHash('HEX');
    },
    base58ToHex(string) {

jssha

jsSHA implements the complete Secure Hash Standard (SHA) family (SHA-1, SHA-224/256/384/512, SHA3-224/256/384/512, SHAKE128/256, cSHAKE128/256, and KMAC128/256) with HMAC

BSD-3-Clause
Latest version published 1 year ago

Package Health Score

73 / 100
Full package analysis

Popular jssha functions