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

242
Vistas
JavaScript encrypted xml throws error in Java application decryption: Given final block not properly padded. Such issues can arise if a bad key is

We have a sender application (node.js) which sends to a Java application some symmetric encrypted XML strings with an AES 128 key.

When the Java application tries to decrypt the content with the provided key the following error will be thrown:

javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption. at com.sun.crypto.provider.CipherCore.unpad(CipherCore.java:975) at com.sun.crypto.provider.CipherCore.fillOutputBuffer(CipherCore.java:1056) at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:853) at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446) at javax.crypto.Cipher.doFinal(Cipher.java:2168)

public generateKey(): Buffer {
    return crypto.generateKeySync('aes', { length: 128 }).export();
}

// Encrypt content with key
public encryptSymmetric(content: string, encryptionKey: Buffer): Buffer {
    const iv = Buffer.from(crypto.randomBytes(this.IV_LENGTH)).toString('hex').slice(0, this.IV_LENGTH);
    const cipher = crypto.createCipheriv('aes-128-cbc', encryptionKey, iv);
    let encrypted = cipher.update(content);

    encrypted = Buffer.concat([encrypted, cipher.final()]);
    return encrypted;
    //return iv + ':' + encrypted.toString('hex');
}

Java receiver: decrypt with key

private static byte[] decryptContent(SecretKeySpec key, byte[] content) throws GeneralSecurityException {
    Cipher cipher = Cipher.getInstance('AES');
    cipher.init(Cipher.DECRYPT_MODE, key);
    return cipher.doFinal(content); // EXCEPTION
}

I have no idea to solve this specific problem, at encryption level there many different options like AES CBC or GCM. I hope you can help me. We can change only the sender code!

about 4 years ago · Juan Pablo Isaza
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