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

285
Visualizações
Can we do a number to number encryption and decryption in javascript/nodejs without converting it to a string value?

I have a field in mongo which is of number type and I want to encrypt it into a unique number to save it and then decrypt it back to the original number without converting it to a string value.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can create a Buffer object, write a Javascript number to the Buffer (creating a binary set of bytes) and then encrypt the contents of the buffer. Then, save the encrypted binary data from the buffer in your database.

To decrypt, you can reverse the process by reading the binary from the database into a Buffer, decrypt the buffer and then read the number from it.

You can write a Javascript number to a Buffer with something like:

buf.writeDoubleBE(value[, offset])

and there's a complementary method for reading a number from the buffer.


So, this doesn't have to be converted to a string anywhere, but it is converted to a binary Buffer.

FYI, here's an article on encrypting strings, buffers and streams in nodejs: https://attacomsian.com/blog/nodejs-encrypt-decrypt-data


FYI, MongoDB has some built-in encryption options (depending upon what storage engine you're using). This is more like database-level encryption that protects the whole database on disk rather than encrypting individual fields. Here's some info on that: https://docs.mongodb.com/manual/core/security-encryption-at-rest/#std-label-encrypted-storage-engine.

The MongoDB doc also has some info on client-side encrypting of individual fields here: https://docs.mongodb.com/manual/core/security-client-side-encryption/

and here:

https://docs.mongodb.com/manual/core/security-explicit-client-side-encryption/

And, apparently the enterprise version of mongodb 4.2 or later has some automatic field level encryption.

about 4 years ago · Juan Pablo Isaza 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