[GH-ISSUE #2015] [feature]: how to use sha256 in Pre-request Scripts Scripts #657

Closed
opened 2026-03-16 16:32:19 +03:00 by kerem · 16 comments
Owner

Originally created by @zlay0701 on GitHub (Dec 16, 2021).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/2015

Originally assigned to: @jamesgeorge007 on GitHub.

Is there an existing issue for this?

  • I have searched the existing issues

Summary

how to use sha256 in Pre-request Scripts Scripts?

Why should this be worked on?

Some interfaces need to dynamically generate signatures and initiate requests according to tokens
The signature algorithm uses algorithms such as sha256 and SHA1

Originally created by @zlay0701 on GitHub (Dec 16, 2021). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/2015 Originally assigned to: @jamesgeorge007 on GitHub. ### Is there an existing issue for this? - [X] I have searched the existing issues ### Summary how to use sha256 in Pre-request Scripts Scripts? ### Why should this be worked on? Some interfaces need to dynamically generate signatures and initiate requests according to tokens The signature algorithm uses algorithms such as sha256 and SHA1
kerem 2026-03-16 16:32:19 +03:00
Author
Owner

@liyasthomas commented on GitHub (Dec 16, 2021):

Similar issue: #2001
Adding support to npm packages and SDKs are in our roadmap. Stay tuned for product updates.

<!-- gh-comment-id:995451572 --> @liyasthomas commented on GitHub (Dec 16, 2021): Similar issue: #2001 Adding support to ~npm packages~ and SDKs are in our roadmap. Stay tuned for product updates.
Author
Owner

@apptut commented on GitHub (Dec 19, 2021):

npm packages +1, I want gen sign with params by md5 or sha1

<!-- gh-comment-id:997340569 --> @apptut commented on GitHub (Dec 19, 2021): npm packages +1, I want gen sign with params by md5 or sha1
Author
Owner

@AndrewBastin commented on GitHub (Dec 19, 2021):

Hate to burst the bubble, but I am not planning on getting NPM packages as is to work with Hoppscotch scripting environment.
It's a complicated enough task as is and implementing mechanisms to manage NPM and node_modules and dependency management and Node Module Resolution capabilities (remember, the scripts are executed client side in a sandbox) all within the sandbox is a massive challenge which we cannot spend too much effort on.

But, I was hoping to get Deno style ESM URL imports working so you can directly import from URL (read more here: https://deno.land/manual/examples/import_export) and there are sources like JSPM, Skypack and Unpkg (as an option) which give all the important libraries in the ESM format.

<!-- gh-comment-id:997397048 --> @AndrewBastin commented on GitHub (Dec 19, 2021): Hate to burst the bubble, but I am not planning on getting NPM packages as is to work with Hoppscotch scripting environment. It's a complicated enough task as is and implementing mechanisms to manage NPM and node_modules and dependency management and Node Module Resolution capabilities (remember, the scripts are executed client side in a sandbox) all within the sandbox is a massive challenge which we cannot spend too much effort on. But, I was hoping to get Deno style ESM URL imports working so you can directly import from URL (read more here: [https://deno.land/manual/examples/import_export](https://deno.land/manual/examples/import_export)) and there are sources like [JSPM](https://jspm.io), [Skypack](https://skypack.dev) and [Unpkg (as an option)](https://unpkg.com) which give all the important libraries in the ESM format.
Author
Owner

@apptut commented on GitHub (Dec 20, 2021):

I agree with what you said. My purpose is not to import npm, but to get the capabilities of encryption libraries. Many times the interface needs to be signed using md5, or sha1, base64 algorithms, and so on.

<!-- gh-comment-id:997856341 --> @apptut commented on GitHub (Dec 20, 2021): I agree with what you said. My purpose is not to import npm, but to get the capabilities of encryption libraries. Many times the interface needs to be signed using md5, or sha1, base64 algorithms, and so on.
Author
Owner

@zlay0701 commented on GitHub (Jan 11, 2022):

can add https://github.com/brix/crypto-js ?

<!-- gh-comment-id:1009662736 --> @zlay0701 commented on GitHub (Jan 11, 2022): can add https://github.com/brix/crypto-js ?
Author
Owner

@evanlurvey commented on GitHub (Mar 6, 2023):

I also have needed crypto-js before for auth and signatures.

<!-- gh-comment-id:1456854748 --> @evanlurvey commented on GitHub (Mar 6, 2023): I also have needed crypto-js before for auth and signatures.
Author
Owner

@sneha-herle commented on GitHub (Aug 10, 2023):

Please find a solution for this, needed crypto-js before for auth and signatures.

<!-- gh-comment-id:1672863801 --> @sneha-herle commented on GitHub (Aug 10, 2023): Please find a solution for this, needed crypto-js before for auth and signatures.
Author
Owner

@bappleug-tw commented on GitHub (Aug 26, 2023):

Plus one for adding crypto-js support

<!-- gh-comment-id:1694207535 --> @bappleug-tw commented on GitHub (Aug 26, 2023): Plus one for adding crypto-js support
Author
Owner

@jhoos70 commented on GitHub (Oct 18, 2023):

Need crypto-js, too. Without it hoppscotch is useless for my usecase.

<!-- gh-comment-id:1768590015 --> @jhoos70 commented on GitHub (Oct 18, 2023): Need crypto-js, too. Without it hoppscotch is useless for my usecase.
Author
Owner

@samuel-deal-tisseo commented on GitHub (Oct 19, 2023):

Plus one for adding crypto-js support

<!-- gh-comment-id:1771189919 --> @samuel-deal-tisseo commented on GitHub (Oct 19, 2023): Plus one for adding crypto-js support
Author
Owner

@qichengri commented on GitHub (Jan 5, 2024):

Plus one for adding crypto-js support

<!-- gh-comment-id:1877926344 --> @qichengri commented on GitHub (Jan 5, 2024): Plus one for adding crypto-js support
Author
Owner

@archcorsair commented on GitHub (Apr 15, 2024):

Any updates on this? This feature is the only one preventing us from moving from postman to hoppscotch

<!-- gh-comment-id:2057657737 --> @archcorsair commented on GitHub (Apr 15, 2024): Any updates on this? This feature is the only one preventing us from moving from postman to hoppscotch
Author
Owner

@siniradam commented on GitHub (May 7, 2024):

Seems like some crypto features available in the browser API working, if you someone is in dire need of HMAC, maybe can give it a try to this function.

async function createHMAC(payload, secret) {
  if (typeof payload == "object") {
    payload = JSON.stringify(payload);
  }
  let enc = new TextEncoder("utf-8");
  let algorithm = { name: "HMAC", hash: "SHA-256" };
  let key = await crypto.subtle.importKey("raw", enc.encode(secret), algorithm, false, [
    "sign",
    "verify",
  ]);
  let signature = await crypto.subtle.sign(algorithm.name, key, enc.encode(payload));
  let digest = btoa(String.fromCharCode(...new Uint8Array(signature)));
  return digest;
}
<!-- gh-comment-id:2098885611 --> @siniradam commented on GitHub (May 7, 2024): Seems like some crypto features available in the browser API working, if you someone is in dire need of HMAC, maybe can give it a try to this function. ```js async function createHMAC(payload, secret) { if (typeof payload == "object") { payload = JSON.stringify(payload); } let enc = new TextEncoder("utf-8"); let algorithm = { name: "HMAC", hash: "SHA-256" }; let key = await crypto.subtle.importKey("raw", enc.encode(secret), algorithm, false, [ "sign", "verify", ]); let signature = await crypto.subtle.sign(algorithm.name, key, enc.encode(payload)); let digest = btoa(String.fromCharCode(...new Uint8Array(signature))); return digest; } ```
Author
Owner

@alizufan commented on GitHub (Jun 27, 2024):

Seems like some crypto features available in the browser API working, if you someone is in dire need of HMAC, maybe can give it a try to this function.

async function createHMAC(payload, secret) {
  if (typeof payload == "object") {
    payload = JSON.stringify(payload);
  }
  let enc = new TextEncoder("utf-8");
  let algorithm = { name: "HMAC", hash: "SHA-256" };
  let key = await crypto.subtle.importKey("raw", enc.encode(secret), algorithm, false, [
    "sign",
    "verify",
  ]);
  let signature = await crypto.subtle.sign(algorithm.name, key, enc.encode(payload));
  let digest = btoa(String.fromCharCode(...new Uint8Array(signature)));
  return digest;
}

thank you !

<!-- gh-comment-id:2195452395 --> @alizufan commented on GitHub (Jun 27, 2024): > Seems like some crypto features available in the browser API working, if you someone is in dire need of HMAC, maybe can give it a try to this function. > > ```js > async function createHMAC(payload, secret) { > if (typeof payload == "object") { > payload = JSON.stringify(payload); > } > let enc = new TextEncoder("utf-8"); > let algorithm = { name: "HMAC", hash: "SHA-256" }; > let key = await crypto.subtle.importKey("raw", enc.encode(secret), algorithm, false, [ > "sign", > "verify", > ]); > let signature = await crypto.subtle.sign(algorithm.name, key, enc.encode(payload)); > let digest = btoa(String.fromCharCode(...new Uint8Array(signature))); > return digest; > } > ``` thank you !
Author
Owner

@jamesgeorge007 commented on GitHub (Nov 6, 2025):

Hi! #5090 added the ability to import ESM packages in the scripting context as part of the Experimental scripting sandbox. You can now import crypto libraries directly:

import CryptoJS from 'https://esm.run/crypto-js@4.2.0';

We're aware of certain limitations with the native crypto module. ESM imports offer an alternative approach. Ongoing scripting improvements are tracked in #5221.

In the meantime, you can choose to proceed with either of the following:

  • Use ESM imports with the Experimental scripting sandbox.
  • Opt out of the experimental scripting sandbox from settings to use the native crypto module.
    Image
<!-- gh-comment-id:3498557120 --> @jamesgeorge007 commented on GitHub (Nov 6, 2025): Hi! #5090 added the ability to import ESM packages in the scripting context as part of the `Experimental scripting sandbox`. You can now import crypto libraries directly: ```ts import CryptoJS from 'https://esm.run/crypto-js@4.2.0'; ``` We're aware of certain limitations with the native `crypto` module. ESM imports offer an alternative approach. Ongoing scripting improvements are tracked in #5221. In the meantime, you can choose to proceed with either of the following: - Use ESM imports with the `Experimental scripting sandbox`. - Opt out of the experimental scripting sandbox from settings to use the native `crypto` module. <img width="1906" height="565" alt="Image" src="https://github.com/user-attachments/assets/bb540bb1-4ec4-46b1-99be-da832a7c6adc" />
Author
Owner

@jamesgeorge007 commented on GitHub (Jan 28, 2026):

Closing as this is addressed in v2026.1.0 via #5791.

<!-- gh-comment-id:3811238200 --> @jamesgeorge007 commented on GitHub (Jan 28, 2026): Closing as this is addressed in [v2026.1.0](https://github.com/hoppscotch/hoppscotch/releases/tag/2026.1.0) via #5791.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#657
No description provided.