Postman生成加密哈希给出错误:typeError:crypto.createhash不是一个函数

发布于 2025-02-11 00:04:41 字数 1302 浏览 2 评论 0原文

我正在尝试通过转换以下TS代码来创建邮递员的先决条件。

import crypto from 'crypto';

const createTestingUserHash = (emailAddress: string, timestamp: string, salt: string) =>
  crypto
    .createHash('sha256')
    .update(`testinguserhash::${emailAddress}::${timestamp}::${salt}`)
    .digest('base64');

export const getLoginLink = async (email: string): Promise<string | undefined> => 
{

  const currentTimeStamp = new Date().toISOString();
  const testingHash = createTestingUserHash(email, currentTimeStamp, testingUserSalt);
  .
  .
  .

我的Postman脚本:

const crypto = require('crypto-js');

const signToken = () => {
    const timestamp = "2022-06-23T14:51:34.694Z";
    const salt = "salt_value";
    const email = "[email protected]";

    var hash = crypto.createHash('sha256').update(`testinguserhash::${emailAddress}::${timestamp}::${salt}`).digest("base64");
    return (hash);
}

const signedToken = signToken();
console.log(`successfully generated hash : ${signedToken}`)

我还尝试了var hash = crypto.createhmac('sha256',“ secret”)。update(“ message”)。digest('base64');,但Postman丢下了类似的错误。

有人可以帮我构建这个脚本吗?

I am trying to create a Postman pre-requisite script by converting the below TS code.

import crypto from 'crypto';

const createTestingUserHash = (emailAddress: string, timestamp: string, salt: string) =>
  crypto
    .createHash('sha256')
    .update(`testinguserhash::${emailAddress}::${timestamp}::${salt}`)
    .digest('base64');

export const getLoginLink = async (email: string): Promise<string | undefined> => 
{

  const currentTimeStamp = new Date().toISOString();
  const testingHash = createTestingUserHash(email, currentTimeStamp, testingUserSalt);
  .
  .
  .

My Postman script:

const crypto = require('crypto-js');

const signToken = () => {
    const timestamp = "2022-06-23T14:51:34.694Z";
    const salt = "salt_value";
    const email = "[email protected]";

    var hash = crypto.createHash('sha256').update(`testinguserhash::${emailAddress}::${timestamp}::${salt}`).digest("base64");
    return (hash);
}

const signedToken = signToken();
console.log(`successfully generated hash : ${signedToken}`)

I also tried var hash = crypto.createHmac('SHA256', "secret").update("Message").digest('base64'); but Postman throws a similar error.

Can someone help me build this script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福还没到 2025-02-18 00:04:41

加密-JS具有完全不同的,但是与node.js crypto库

等效的crypto-js代码是

const crypto = require('crypto-js');

const signToken = () => {
    const timestamp = "2022-06-23T14:51:34.694Z";
    const salt = "salt_value";
    const emailAddress = "[email protected]";

    return crypto.SHA256(`testinguserhash::${emailAddress}::${timestamp}::${salt}`).toString(crypto.enc.Base64);
}

const signedToken = signToken();
console.log(`successfully generated hash : ${signedToken}`)

crypto-js has a completely different but well documented interface compared to node.js crypto library

The equivalent crypto-js code is

const crypto = require('crypto-js');

const signToken = () => {
    const timestamp = "2022-06-23T14:51:34.694Z";
    const salt = "salt_value";
    const emailAddress = "[email protected]";

    return crypto.SHA256(`testinguserhash::${emailAddress}::${timestamp}::${salt}`).toString(crypto.enc.Base64);
}

const signedToken = signToken();
console.log(`successfully generated hash : ${signedToken}`)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文