Getting ShortBufferException when using CipherOutputStream with AES GCM mode
I’m trying to write an encrypter/decrypter class that encrypts and decrypts files. My server receives the file as an InputStream
, and I want to store it at a particular path, so those are the inputs to my encrypt()
method. For testing purposes, encrypt()
generates a new key for each file and stores it in a map with the file’s path. My decrypt()
method just takes the file name and attempts to print the file contents as a string. encrypt()
seems to work fine. The problem I’m running into is that when I call decrypt()
with the file name, I get a ShortBufferException. I’ve tried changing the buffer size in my BufferedReader, but to no avail. I think I’m missing something fundamental about how CipherInputStream
or InputStream
s in general work. Any thoughts would be much appreciated! Here’s my FileEncrypterDecrypter
class: