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

856
Views
Cifrado AES de Java a Node.js

Necesito replicar el código de cifrado de Java usando AES/EAX/NoPadding con el proveedor BouncyCastle en node.js. El valor cifrado todavía tendrá que ser descifrado por el descifrado de Java heredado, por lo que los bytes salt e iv deben mantener la misma longitud. En el código node.js , puedo generar la clave secreta y de sal correctamente. Pero tengo un problema. ¿Cuál es el algoritmo equivalente a AES/EAX/NoPadding con BouncyCastle ?

Java existente:

 import org.bouncycastle.jce.provider.BouncyCastleProvider; import java.security.SecureRandom; import java.text.Normalizer; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec; import javax.crypto.SecretKey; import javax.crypto.Cipher; public byte[] encrypt(byte[] plaintext, char[] password) { byte[] saltBytes = "SaltString1234!".getBytes("UTF-8"); final byte[] salt = new byte[16]; System.arraycopy(saltBytes, 0, salt, 0, 16); SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); random.setSeed(System.currentTimeMillis()); byte[] iv = new byte[8]; // random.nextBytes(iv); String normalizedPassword = Normalizer.normalize(new String(password), Normalizer.Form.NFC); char[] currentPassword = normalizedPassword.toCharArray(); PBEKeySpec keySpec = new PBEKeySpec(currentPassword, salt, 1000, 128); SecretKey derivedKey = newSecretKey("PBKDF2WithHmacSHA1", keySpec); SecretKey secretKey = new SecretKeySpec(derivedKey.getEncoded(), "AES"); Provider provider = new BouncyCastleProvider(); Cipher cipher = newCipher("AES/EAX/NoPadding", provider); final IvParameterSpec ivParamSpec = new IvParameterSpec(iv); cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivParamSpec); return cipher.doFinal(plaintext); }

Nuevo código node.js:

 const crypto = require('crypto'); function encrypt(plaintext, password) { const salt = Buffer.from('SaltString1234!', 'utf8').subarray(0,16); const secretKey = crypto.pbkdf2Sync(password.normalize('NFC'), salt, 1000, 16, 'sha1'); const iv = crypto.randomBytes(8); const cipher = crypto.createCipheriv( 'aes-128-gcm'/* What algorithm be equivilent to AES/EAX/NoPadding with BouncyCastle? */, secretKey, iv ); const ciphertextWithTag = Buffer.concat([ iv, cipher.update(plaintext, 'utf8'), cipher.final(), cipher.getAuthTag() ]); return ciphertextWithTag; }
about 4 years ago · Juan Pablo Isaza
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!