當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript crypto.createHash函數代碼示例

本文整理匯總了TypeScript中crypto.createHash函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createHash函數的具體用法?TypeScript createHash怎麽用?TypeScript createHash使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了createHash函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: resolve

	return new Promise<string>(resolve => {
		try {
			let interfaces = os.networkInterfaces();
			let mac;
			for (let key of Object.keys(interfaces)) {
				let item = interfaces[key][0];
				if (!item.internal) {
					mac = item.mac;
					break;
				}
			}
			if (mac) {
				resolve(crypto.createHash('sha256').update(mac + os.homedir(), 'utf8').digest('hex'));
			} else {
				resolve(generateGuid());
			}
		} catch (err) {
			resolve(generateGuid()); // fallback
		}
	});
開發者ID:jumpinjackie,項目名稱:sqlopsstudio,代碼行數:20,代碼來源:utils.ts

示例2: function

const onRequest: Hapi.ServerExtRequestHandler = function (request, reply) {

    const hash = Crypto.createHash('sha1');
    request.on('peek', (chunk) => {

        hash.update(chunk);
    });

    request.once('finish', () => {

        console.log(hash.digest('hex'));
    });

    request.once('disconnect', () => {

        console.error('request aborted');
    });

    return reply.continue();
};
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:20,代碼來源:event-types.ts

示例3:

const onRequest: Lifecycle.Method = (request, h) => {
    /*
     * Server events
     */
    request.server.events.on('request', (request: Request, event: any, tags: any) => {
        console.log(request.paramsArray);
        console.log(event);
        console.log(tags);
    });

    request.server.events.on('response', (request: Request) => {
        console.log('Response sent for request: ' + request.path);
    });

    request.server.events.on('start', () => {
        console.log('Server started');
    });

    request.server.events.once('stop', () => {
        console.log('Server stoped');
    });

    /*
     * Request events
     */
    const hash = Crypto.createHash('sha1');

    request.events.on("peek", (chunk) => {
        hash.update(chunk);
    });

    request.events.once("finish", () => {
        console.log(hash.digest('hex'));
    });

    request.events.once("disconnect", () => {
        console.error('request aborted');
    });

    return h.continue;
};
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:41,代碼來源:event-types.ts

示例4:

const normalizeMissingOptions = (
  options: Config.InitialOptions,
  configPath: Config.Path | null | undefined,
  projectIndex: number,
): Config.InitialOptions => {
  if (!options.name) {
    options.name = crypto
      .createHash('md5')
      .update(options.rootDir)
      // In case we load config from some path that has the same root dir
      .update(configPath || '')
      .update(String(projectIndex))
      .digest('hex');
  }

  if (!options.setupFiles) {
    options.setupFiles = [];
  }

  return options;
};
開發者ID:Volune,項目名稱:jest,代碼行數:21,代碼來源:normalize.ts

示例5: safeBuild

function safeBuild()
{
	console.log('files changed, start building');
	try
	{
		let _build_result = build();
		let _build_time = Date.now().toString() + Math.random().toString();
		let md5 = crypto.createHash('md5');
		build_result = _build_result;
		md5.update(build_result.body, 'utf8');
		md5.update(build_result.css, 'utf8');
		md5.update(build_result.javascript, 'utf8');
		build_version = md5.digest('hex');
		console.log('build ok. version=', build_version);
	}
	catch (e)
	{
		console.error('build error:', e);
		notifyToBuild();
	}
}
開發者ID:hUangDDD,項目名稱:bally,代碼行數:21,代碼來源:builder.ts

示例6:

app.post("/pop/search", (req, res) => {
    console.log("post /dot/search");
    // CREATE TABLE usanpn2.Pop_Search (Search_ID INT(11) NOT NULL AUTO_INCREMENT, Hash TEXT, Json TEXT, Save_Count INT(11), PRIMARY KEY(Search_ID));
    let foundHash = false;
    let saveCount = 1;
    let saveJson = JSON.stringify(req.body.searchJson);
    let hashedJson = crypto.createHash("md5").update(saveJson).digest("hex");
    pool.getConnection((err: any, connection: any) => {
        if (err) {
            console.error(err);
            res.send(null);
            connection.release();
        }
        else {
            connection.query("SELECT * from Pop_Search WHERE Hash = ?", hashedJson, (err: any, result: any) => {
                if (err) throw err;
                if (result[0]) {
                    foundHash = true;
                    saveCount = result[0].Save_Count;
                }
                if (!foundHash) {
                    let popSearch = {Hash: hashedJson, Json: saveJson, Save_Count: saveCount};
                    connection.query("INSERT INTO Pop_Search SET ?", popSearch, (err: any, result: any) => {
                        if (err) throw err;
                        console.log("Last insert:", result);
                        res.send({saved_search_hash: hashedJson});
                    });
                }
                else {
                    connection.query("Update Pop_Search SET Save_count = ? WHERE Hash = ?", [saveCount + 1, hashedJson], (err: any, result: any) => {
                        if (err) throw err;
                        console.log("Last insert:", result);
                        res.send({saved_search_hash: hashedJson});
                    });
                }
                connection.release();
            });
        }
    });
});
開發者ID:usa-npn,項目名稱:pop-service,代碼行數:40,代碼來源:server.ts

示例7: once

	const promise = new Promise<string | undefined>((c, e) => {
		const input = fs.createReadStream(path);
		const hash = crypto.createHash('sha1');
		const hashStream = hash as any as stream.PassThrough;
		input.pipe(hashStream);

		const done = once((err?: Error, result?: string) => {
			input.removeAllListeners();
			hashStream.removeAllListeners();

			if (err) {
				e(err);
			} else {
				c(result);
			}
		});

		input.once('error', done);
		input.once('end', done);
		hashStream.once('error', done);
		hashStream.once('data', (data: Buffer) => done(undefined, data.toString('hex')));
	});
開發者ID:,項目名稱:,代碼行數:22,代碼來源:

示例8: resolve

  return new Promise<ScanResults>(async (resolve, reject) => {
    // return a valid, if fake, result when there are no js files to hash.
    if (fileList.length === 0) {
      resolve(new ScanResultsImpl({}, new Map(), 'EMPTY-no-js-files'));
      return;
    }

    // TODO: Address the case where the array contains `undefined`.
    const hashes: Array<string | undefined> = [];
    const statistics: ScanStats = {};
    const errors: Map<string, Error> = new Map<string, Error>();

    for (const filename of fileList) {
      try {
        const fileStats = await statsForFile(filename, !precomputedHash);
        if (!precomputedHash) {
          hashes.push(fileStats.hash);
        }
        statistics[filename] = fileStats;
      } catch (err) {
        errors.set(filename, err);
      }
    }

    let hash: string;
    if (!precomputedHash) {
      // Sort the hashes to get a deterministic order as the files may
      // not be in the same order each time we scan the disk.
      const buffer = hashes.sort().join();
      const sha1 = crypto
        .createHash('sha1')
        .update(buffer)
        .digest('hex');
      hash = 'SHA1-' + sha1;
    } else {
      hash = precomputedHash!;
    }
    resolve(new ScanResultsImpl(statistics, errors, hash));
  });
開發者ID:GoogleCloudPlatform,項目名稱:cloud-debug-nodejs,代碼行數:39,代碼來源:scanner.ts

示例9: Promise

  return new Promise((resolve, reject) => {
    const pack = tarStream.pack()

    const outDir = path.dirname(outFile)
    if (!fs.existsSync(outDir)) {
      fs.mkdirpSync(outDir)
    }

    for (const { rootDir, files } of manifest) {
      for (const file of files) {
        const stat = fs.statSync(file)
        if (!stat.isFile()) {
          continue
        }
        const name = path.relative(rootDir, file)
        pack.entry({ name }, fs.readFileSync(file))
      }
    }

    pack.finalize()
    const gzip = zlib.createGzip()
    const outStream = fs.createWriteStream(outFile)
    const bundleHash = createHash("sha1").setEncoding("hex")
    pack.pipe(bundleHash)
    const gzStream = pack.pipe(gzip)
    gzStream.pipe(outStream)

    gzStream.on("end", () => {
      bundleHash.end()
      outStream.end()

      resolve({
        path: outFile,
        digest: bundleHash.read().toString(),
        byteLength: outStream.bytesWritten
      })
    })
  })
開發者ID:dianpeng,項目名稱:fly,代碼行數:38,代碼來源:tarball.ts

示例10: add

    add('extension.startGhcid', () => {
        if (!vscode.workspace.rootPath) {
            vscode.window.showWarningMessage("You must open a workspace first.")
            return null;
        }
        // hashing the rootPath ensures we create a finite number of temp files
        var hash = crypto.createHash('sha256').update(vscode.workspace.rootPath).digest('hex').substring(0, 20);
        let file = path.join(os.tmpdir(), "ghcid-" + hash + ".txt");
        context.subscriptions.push({dispose: () => {try {fs.unlinkSync(file);} catch (e) {};}});
        fs.writeFileSync(file, "");

        let ghcidCommand : string = vscode.workspace.getConfiguration('ghcid').get('command');

        let opts : vscode.TerminalOptions =
            os.type().startsWith("Windows") ?
                {shellPath: "cmd.exe", shellArgs: ["/k", ghcidCommand]} :
                {shellPath: ghcidCommand, shellArgs: []};
        opts.name = "ghcid";
        opts.shellArgs.push("--outputfile=" + file);
        oldTerminal = vscode.window.createTerminal(opts);
        oldTerminal.show();
        return watchOutput(vscode.workspace.rootPath, file);
    });
開發者ID:ndmitchell,項目名稱:ghcid,代碼行數:23,代碼來源:extension.ts


注:本文中的crypto.createHash函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。