Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
Leer un binario con javascript

¿Cómo puedo leer un binario como el siguiente?

 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 }

Intenté varias cosas como hacer un parseInt:

error: NaN

o con el nuevo 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;

¿Alguien puede ayudarme a leer el búfer de este binario y descifrar mis datos aes?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Realmente no especificó el formato del archivo, para este caso creé un código, puede modificarlo si lo necesita para otros casos (Mi código ahora solo extrae los números de "[" a "]" con 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 Denunciar

0

Vale, soy estúpido. Encontré la solución.

1. Cifre y establezca datos con hex() en mongoDB de esta manera:

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

2. Datos de formato de cadena en mongoDB:

 b9314d7b7f24e79bc08518e956f9125a

3. Transforme la cadena hexadecimal en una matriz de bytes y descifre los datos de 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()

Gracias por tu ayuda !

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda