[GH-ISSUE #5868] [bug]: Web Crypto API RSA-OAEP Encryption Code Throws Error #2306

Open
opened 2026-03-16 23:54:36 +03:00 by kerem · 1 comment
Owner

Originally created by @chenc4 on GitHub (Feb 12, 2026).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/5868

Is there an existing issue for this?

  • I have searched existing issues and this bug hasn't been reported yet

Platform

Desktop App

Browser

Edge

Operating System

Windows

Bug Description

What happend?

Console reports error message: "Encryption failed: crypto.subtle.importKey is not available (requires WebCrypto)"

Steps to reproduce

  1. Set 3 variables in Hoppscotch: app_code, public_key (SPKI-format Base64 public key), user_name;
  2. the Experimental scripting sandbox is Enabled.
  3. Paste the following code into the Pre-request Script section:
// Get variables from Hoppscotch
const appCode = hopp.request.variables.get("app_code");
const publicKeyOri = hopp.request.variables.get("public_key");
const userName = hopp.request.variables.get("user_name");

  // Build JSON string
  const json = JSON.stringify({
      appCode: appCode,
      loginName: userName,
  });

  console.log("Data to encrypt:", json);
  console.log("Public key:", publicKeyOri);

  // Decode Base64 public key
  const binaryDer = Uint8Array.from(atob(publicKeyOri), (c) => c.charCodeAt(0));

  // Import public key (Promise chain)
  crypto.subtle.importKey(
      "spki",
      binaryDer,
      {
          name: "RSA-OAEP",
          hash: { name: "SHA-256" },
      },
      false,
      ["encrypt"],
  )
  .then((publicKey) => {
      const encoder = new TextEncoder();
      const data = encoder.encode(json);
      return crypto.subtle.encrypt({ name: "RSA-OAEP" }, publicKey, data);
  })
  .then((encrypted) => {
      const uintArray = new Uint8Array(encrypted);
      let binaryString = "";
      for (let i = 0; i < uintArray.length; i++) {
          binaryString += String.fromCharCode(uintArray[i]);
      }
      const encryptedBase64 = btoa(binaryString);
      console.log("Encryption completed, password:", encryptedBase64);
      hopp.env.set("password", encryptedBase64);
  })
  .catch((error) => {
      console.error("Encryption failed:", error.message, error.stack);
  });

Deployment Type

Self-hosted (on-prem deployment)

Version

26.1.1

Originally created by @chenc4 on GitHub (Feb 12, 2026). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/5868 ### Is there an existing issue for this? - [x] I have searched existing issues and this bug hasn't been reported yet ### Platform Desktop App ### Browser Edge ### Operating System Windows ### Bug Description ## What happend? Console reports error message: "Encryption failed: crypto.subtle.importKey is not available (requires WebCrypto)" ## Steps to reproduce 1. Set 3 variables in Hoppscotch: `app_code`, `public_key` (SPKI-format Base64 public key), `user_name`; 2. the Experimental scripting sandbox is Enabled. 3. Paste the following code into the **Pre-request Script** section: ```javascript // Get variables from Hoppscotch const appCode = hopp.request.variables.get("app_code"); const publicKeyOri = hopp.request.variables.get("public_key"); const userName = hopp.request.variables.get("user_name"); // Build JSON string const json = JSON.stringify({ appCode: appCode, loginName: userName, }); console.log("Data to encrypt:", json); console.log("Public key:", publicKeyOri); // Decode Base64 public key const binaryDer = Uint8Array.from(atob(publicKeyOri), (c) => c.charCodeAt(0)); // Import public key (Promise chain) crypto.subtle.importKey( "spki", binaryDer, { name: "RSA-OAEP", hash: { name: "SHA-256" }, }, false, ["encrypt"], ) .then((publicKey) => { const encoder = new TextEncoder(); const data = encoder.encode(json); return crypto.subtle.encrypt({ name: "RSA-OAEP" }, publicKey, data); }) .then((encrypted) => { const uintArray = new Uint8Array(encrypted); let binaryString = ""; for (let i = 0; i < uintArray.length; i++) { binaryString += String.fromCharCode(uintArray[i]); } const encryptedBase64 = btoa(binaryString); console.log("Encryption completed, password:", encryptedBase64); hopp.env.set("password", encryptedBase64); }) .catch((error) => { console.error("Encryption failed:", error.message, error.stack); }); ``` ### Deployment Type Self-hosted (on-prem deployment) ### Version 26.1.1
Author
Owner

@deBilla commented on GitHub (Mar 14, 2026):

The fix was already implemented in PR #5791 (merged Jan 22, 2026), which added the full Web Crypto API to the experimental scripting sandbox.
https://github.com/hoppscotch/hoppscotch/pull/5791

<!-- gh-comment-id:4060257111 --> @deBilla commented on GitHub (Mar 14, 2026): The fix was already implemented in PR #5791 (merged Jan 22, 2026), which added the full Web Crypto API to the experimental scripting sandbox. https://github.com/hoppscotch/hoppscotch/pull/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#2306
No description provided.