Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
Encrypt large data

Following code works fine when I encrypt 190 bytes or less. But if I try 191 or more, an exception is thrown. What is the right way of encrypting larger pieces of data?

async function go(size) {
  var { publicKey, privateKey } = await crypto.subtle.generateKey({
    name: "RSA-OAEP",
    modulusLength: 2048,
    publicExponent: new Uint8Array([1, 0, 1]),
    hash: "SHA-256",
  }, true, ["encrypt", "decrypt"])

  try {
    var res = await window.crypto.subtle.encrypt(
      { name: "RSA-OAEP" },
      publicKey,
      new Uint8Array(size),
    )

    console.log(`${size} - OK: ${res.byteLength}`)
  } catch (ex) {
    console.log(`${size} - ERROR: ${ex.constructor.name} ${ex}`)
  }
}

go(10)    // Ok
go(100)   // Ok
go(190)   // Ok
go(191)   // Error
go(200)   // Error
go(500)   // Error

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!