Script haschage sha1 via API

Par Luc Antoine, il y a 2 ans


Bonjour,

J'ai besoind'utilser l'API hashify afin d'effectuer un haschage d'une chaine de caratères.

const password = '123456'; // Générer le timestamp en millisecondes const timestamp = Date.now(); //console.log("timestamp:", timestamp); //définition de la fonction sha1 function sha1(input) { const urlsha1 = `https://api.hashify.net/hash/sha1/hex?value=${input}`; console.log("urlsha1 : ", urlsha1); return fetch(urlsha1) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => data.Digest) .catch(error => { console.error('Error:', error); throw error; // Re-throw the error for further handling if needed }); } // Hashage const dataToHash = `password=${password}&timestamp=${timestamp}`; console.log('To hash ', dataToHash); // SHA1 const sha1Hash = await sha1(dataToHash); console.log('Hash SHA1 :', sha1Hash);

Ce que je veux

il devrai me retouner le hashage de la chaine password=${password}&timestamp=${timestamp}

Ce que j'obtiens

Il me retourne tout le temps la même chaine de caratères.
Je test directement dans postamann et, en creusant, je me rend compte qu'il hasher la chaine password=${password}

Merci pour votre aide !

2 réponses

popotte, il y a 2 ans

Hello :)

Alors apparement tu essayes de hacher cette valeur: https://api.hashify.net/hash/sha1/hex?value=${input};

Ton input c'est: password=${password}&timestamp=${timestamp}

Du coup ça donne: https://api.hashify.net/hash/sha1/hex?value=password=${password}&timestamp=${timestamp}; ton script doit pas apprécier

Retires value= et ça devrait passer :)

Luc Antoine, il y a 2 ans

Merci pour la réponse,

Non je hache cette valeur dataToHash ; "password=${password}&timestamp=${timestamp}" pas toute l'url.
J'ai réussi en remplacant les "&" par des "%26" !