Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
How to encrypt a File on the Clientside for E2E encryption?

Encripting a file on the Client side.

Is the following method a valid and secure way to encrypt files?

Does it work with large files (is the entire file stored in Memory during the process)?

const encryptFile = async (
  file: Blob
): Promise<{ key: CryptoKey; buffer: Buffer }> => {
  const fileBuffer = await file.arrayBuffer();

  const key = await crypto.subtle.generateKey(
    { name: "AES-GCM", length: 128 },
    true, // extractable
    ["encrypt", "decrypt"]
  );

  const encrypted = await crypto.subtle.encrypt(
    { name: "AES-GCM", iv: new Uint8Array(12) /* don't reuse key! */ },
    key,
    fileBuffer
  );

  const buf = Buffer.from(encrypted);

  return { key, buffer: buf };
};

Are there any Better ways?

Why I need it

I want to build an E2E encryption into my file-sharing site. After encrypting the file with the posted method, I upload it to the server as a binary file.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Is it secure? Well, against what?

The code doesn't reuse the key - it claims, and GCM is considered secure.

Not sure why you would be using 128 bits though, 256 bits is generally not much slower or just as fast.

Will the message and ciphertext be in memory?

Blob.prototype.arrayBuffer()

Returns a promise that resolves with an ArrayBuffer containing the entire contents of the Blob as binary data.

So yes. I'd at least zero out that data right after encryption. Furthermore, it very much depends what you now will do with the randomly generated key.

I'd warn against using GCM for too large a file, it is certainly limited to 64 GiB - 32 bytes internally, after that the internal counter will start to repeat. Still sounds large, but since I'm typing this on a computer with 32 GiB of RAM...

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda