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

254
Vistas
Not able to get Iv parameterspec from a String

I am trying to encrypt the message from FE (React Native) and send to BE to decrypt(Java Spring). I use this Hybrid Crypto library to generate cipher text. My logic in FE is using RSA public key to create AES key, and then use this AES key to encrypt my message. I send to my BE encrypted AES key + iv + cipher text
But in Java I cannot read Iv parameterspec, it's always show this message

java.security.InvalidAlgorithmParameterException: Wrong IV length: must be 16 bytes long

This is my Iv, it always returns the same length with different AES standards (AES-ECB, AES-CBC, AES-CFB, AES-OFB, AES-CTR)

merltoPCJMCEu0/yEaMpriIG9Xl4hP3W+h1iNJUndu0=

I did my own research, and I found that the Iv length in Java must always be 16 bytes

But when I decode my String, it always returns 32

System.out.println(Base64.getDecoder().decode("merltoPCJMCEu0/yEaMpriIG9Xl4hP3W+h1iNJUndu0=").length);

This is all of my decrypt code

Security.addProvider(new BouncyCastleProvider());
KeyFactory factory = KeyFactory.getInstance("RSA");
PrivateKey privateKey = generatePrivateKey(factory, RESOURCES_DIR + "private-key.pem");

Cipher decryptCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] keyb = decryptCipher.doFinal(Base64.getDecoder().decode("My AES key"));

SecretKeySpec skey = new SecretKeySpec(keyb, "AES");
IvParameterSpec ivspec = new IvParameterSpec(Base64.getDecoder().decode("My IV string"));
Cipher ci = Cipher.getInstance("AES/CBC/PKCS5Padding");
ci.init(Cipher.DECRYPT_MODE, skey, ivspec);

byte[] decryptOut = ci.doFinal(Base64.getDecoder().decode("My cipher text"));
System.out.println(new String(decryptOut, StandardCharsets.UTF_8));

I really don't know where am I missing...

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