Estoy tratando de crear un script de requisito previo de Postman convirtiendo el siguiente código 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); . . .Mi guión del cartero:
const crypto = require('crypto-js'); const signToken = () => { const timestamp = "2022-06-23T14:51:34.694Z"; const salt = "salt_value"; const email = "testing@test.io"; var hash = crypto.createHash('sha256').update(`testinguserhash::${emailAddress}::${timestamp}::${salt}`).digest("base64"); return (hash); } const signedToken = signToken(); console.log(`successfully generated hash : ${signedToken}`) También probé var hash = crypto.createHmac('SHA256', "secret").update("Message").digest('base64'); pero Postman arroja un error similar.
¿Puede alguien ayudarme a construir este script?
crypto-js tiene una interfaz completamente diferente pero bien documentada en comparación con la biblioteca criptográfica node.js
El código crypto-js equivalente es
const crypto = require('crypto-js'); const signToken = () => { const timestamp = "2022-06-23T14:51:34.694Z"; const salt = "salt_value"; const emailAddress = "testing@test.io"; return crypto.SHA256(`testinguserhash::${emailAddress}::${timestamp}::${salt}`).toString(crypto.enc.Base64); } const signedToken = signToken(); console.log(`successfully generated hash : ${signedToken}`)