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

287
Views
¿Cuál es la forma correcta de generar AES-CBC-192 con CryptoJS?

Llegué al siguiente código y me gustaría saber si esta es una forma correcta y segura de generar un cifrado AES-CBC-192 con CryptoJS:

Código de pregunta original:

 let encrypt = (text,key) => { let salt = "M@Tr05K@"; let iv = CryptoJS.lib.WordArray.random(16); let key_to_bits = CryptoJS.PBKDF2(key,salt,{keySize: 192/8, iterations:30000}); return CryptoJS.AES.encrypt(text,key,{iv:iv}).toString(); } encrypt("Lorem ipsum...","¿MinhaSenha?>Segur@?");

Código con cambios sugeridos:

 let encrypt = (text, key) => { let salt = CryptoJS.lib.WordArray.random(16); let iv = CryptoJS.lib.WordArray.random(16); let key_to_bits = CryptoJS.PBKDF2(key, salt, { keySize: 192 / 32, iterations: 30000 }); return {result : CryptoJS.AES.encrypt(text, key_to_bits, { iv: iv }).toString(), salt:CryptoJS.enc.Hex.stringify(salt), iv:CryptoJS.enc.Hex.stringify(iv) }; } encrypt("Lorem ipsum...", "¿MinhaSenha?>Segur@?");

Gracias por su atención :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

aquí uno que acabo de terminar para AES-CBC-256 desde una contraseña usando PBKdf2, esto está usando Web crypto apihttps://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API

no es lo que está buscando exactamente, pero podría ayudar con la dirección, elimine importKey de abajo y lea en https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey

 function generateKey(passwd, iterations) { var encoder = new TextEncoder('utf-8'); var passphraseKey = encoder.encode(passwd); var saltBuffer = encoder.encode("carthage"); crypto.subtle.importKey( 'raw', passphraseKey, {name: 'PBKDF2'}, false, ['deriveBits', 'deriveKey'] ).then(function(key) { // console.log(key); return window.crypto.subtle.deriveKey( { "name": 'PBKDF2', "salt": saltBuffer, "iterations": iterations, "hash": 'SHA-256' }, key, { "name": 'AES-CBC', "length": 256 }, true, [ "encrypt", "decrypt" ] ) }).then(function (webKey) { // console.log(webKey); return crypto.subtle.exportKey("raw", webKey); }).then(function (buffer) { // console.log(buffer); // console.log(saltBuffer); console.log("Private Key = " + buf2hex(buffer)); console.log("Salt = " + bytesToHexString(saltBuffer)); }); } function buf2hex(buffer) { // buffer is an ArrayBuffer return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join(''); } function bytesToHexString(byteArray) { return Array.prototype.map.call(byteArray, function(byte) { return ('0' + (byte & 0xFF).toString(16)).slice(-2); }).join(''); }
about 4 years ago · Juan Pablo Isaza Report
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!