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

252
Views
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
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!