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

219
Views
Cifrado CryptoJS AES (con tamaño de clave 128/8) equivalente en PHP

Soy novato en PHP y estaba tratando de lograr el equivalente de cifrado CryptoJS AES en PHP. Vi esta publicación pero desafortunadamente no pude lograr lo mismo. Obtuve una salida diferente en el código PHP como cadena cifrada.

¿Qué hice mal?

Código JavaScript

 const customerObject = { CustomerName: "test", EmailID: "tester@test.com", Street: "Test", City: "London", Country: "United Kingdom", ZipCode: "XXX XXX", }; const token = "8056483646328123"; const key = CryptoJS.enc.Utf8.parse(token); const iv = CryptoJS.enc.Utf8.parse(token); const returnEncrypted = CryptoJS.AES.encrypt( CryptoJS.enc.Utf8.parse(customerObject), key, { iv: iv, keySize: 128 / 8, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7, } );

Código PHP

 <?php $customer = [ 'CustomerName' => "test", 'EmailID' => "tester@test.com", 'Street' => "Test", 'City' => "London", 'Country' => "United Kingdom", 'ZipCode' => "XXX XXX", ]; $plaintext = json_encode($customer); $method = 'AES-128-CBC'; $key = hex2bin("8056483646328123"); $iv = hex2bin("8056483646328123"); $ciphertext = openssl_encrypt( $plaintext, $method, $key, OPENSSL_RAW_DATA, $iv ); $ciphertext = base64_encode($ciphertext); echo $ciphertext; ?>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Como señaló @Topaco en los comentarios, la clave y el IV no deben decodificarse en hexadecimal, es decir, eliminar ambos hex2bin().

El código corregido se muestra a continuación.

 <?php $customer = [ 'CustomerName' => "test", 'EmailID' => "tester@test.com", 'Street' => "Test", 'City' => "London", 'Country' => "United Kingdom", 'ZipCode' => "XXX XXX", ]; $plaintext = json_encode($customer); $method = 'AES-128-CBC'; $key = "8056483646328123"; $iv = "8056483646328123"; $ciphertext = openssl_encrypt( $plaintext, $method, $key, OPENSSL_RAW_DATA, $iv ); $ciphertext = base64_encode($ciphertext); echo $ciphertext; ?>
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!