Postman生成加密哈希给出错误:typeError:crypto.createhash不是一个函数
我正在尝试通过转换以下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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
加密-JS具有完全不同的,但是与node.js crypto库
等效的crypto-js代码是
crypto-js has a completely different but well documented interface compared to node.js crypto library
The equivalent crypto-js code is