I’m trying to encrypt and decrypt files using AES/GCM encryption in Java. I have the following code:
...
30. byte[] iv = new byte[GCM_IV_LENGTH];
31. SecureRandom random = new SecureRandom();
32. random.nextBytes(iv);
33. GCMParameterSpec parameterSpec = new GCMParameterSpec(GCM_TAG_LENGTH * 8, iv);
34.
35. cipher.init(Cipher.ENCRYPT_MODE, secretKey, parameterSpec);
// Write file content to CipherOutputStream
...
But line 35 throws the following error:
java.security.InvalidAlgorithmParameterException: Unsupported parameter: javax.crypto.spec.GCMParameterSpec@7de26db8
I’ve looked around for the solution to this but to no avail. Does this simply mean GCM isn’t supported yet and I should revert to a different mode, like CBC? Or am I missing something?
I’m new to encryption so if there’s something I’m misunderstanding conceptually, any clarification would be much appreciated 🙂
Thank you!