Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

253
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda