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

161
Visualizações
Read a binary with javascript

How can i read a binary like bellow ?

Binary2 {
  sub_type: 0,
  buffer: Buffer(16) [
    12,  15,  64, 88, 174,  93,
    16, 250, 162,  5, 122, 223,
    16,  98, 207, 68
  ],
  position: 16
}

I tried several things like making a parseInt:

error: NaN

or with new Uint16Array():

error:

error: TS2769 [ERROR]: No overload matches this call.
  The last overload gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'ArrayBufferLike'.
    console.log('test :', new Uint16Array(contact.firstname))
TS2771 [ERROR]:     The last overload is declared here.
        new(buffer: ArrayBufferLike, byteOffset?: number, length?: number): Uint16Array;

Someone can help me to read the buffer of this binary and decrypt my aes data ?

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

0

You not really specified the file format, for this case I created a code, you can modify if you need to for other cases (My code now just extracting the numbers from "[" to "]" with StrBetween):

 function StrBetween(str, s1, s2){    
     let pos1 = str.indexOf(s1);
     if(pos1>-1){
       pos1 += s1.length;
       return str.substr(pos1, str.indexOf(s2, pos1)-pos1);
     } else {
       return "";
     } 
    } 

  function Convert(){         
    var data = `
      Binary2 {
      sub_type: 0,
      buffer: Buffer(16) [
        12,  15,  64, 88, 174,  93,
        16, 250, 162,  5, 122, 223,
        16,  98, 207, 68
      ],
      position: 16
    }
    `;
    
    let values = StrBetween(data, "[", "]").split(",");
    var uint16 = new Uint16Array(values.length);
    
    for(let i=0; i<values.length; i++){
     values[i] = values[i].replace('\n','').trim(); //Remove line breaks and spaces
     uint16[i] = parseInt(values[i]);
    }
    
    console.log(uint16); //Show the array               
    }
about 4 years ago · Juan Pablo Isaza Relatório

0

Ok,i'm stupid. I found the solution.

1. Encrypt and set data with hex() in mongoDB like this :

let firstname = await aes.encrypt(data.fields.firstname)
data.fields.firstname = firstname.hex()

2. String format data in mongoDB :

b9314d7b7f24e79bc08518e956f9125a

3. Transform hexadecimal string to bytes array and decrypt data from mongoDB :

for (var bytes = [], c = 0; c < contact.firstname.length; c += 2) {
      bytes.push(parseInt(contact.firstname.substr(c, 2), 16));
    }
let cipher = await aes.decrypt(new Uint8Array(bytes))
contact.firstname = cipher.toString()

thanks for your help !

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