Temporary, in-memory, Java files

We have a content management system that allows our users to store files uploaded through the REST web service. Before saving these files to the repository, their contents are encrypted.

When these files are extracted, the contents of the file are decrypted and placed in an array of bytes. The goal is to transfer this content back to the client as an attachment of files that they can store on their local machines.

To do this, I currently store the contents in a temporary file and pass the temp file back as an attachment. This approach had the unpleasant side effect of a previously encrypted repository file, which is stored “in clarity” in the temporary directory.

I know that I can set a temporary file for automatic deletion at the end of the JVM, but since this is a server, there may be a lot of time between server reboots.

I can also (I think) set up some kind of listening task to periodically check the temp directory and delete files for a certain age, but this seems cumbersome and doesn’t really solve the problem - it just reduces the exposure time.

I am looking for alternatives to avoid a temporary file, but still allow the user to download the file (preferably in memory) as an attachment through a web service.

Any idea?

Thank!

+3
source share
5 answers

, , Java-, . HashMap ( , , ). , memcache Java, . ehcache JVM.

, , , , JVM?

+2

Stream ? , .

+2

, File , , ?

: , getName(), getContentStream() .., File.

+1

One thing that you could learn instead of a file is Memcached and delete the file after decrypting it.

Alternatively, you can just save the encrypted file in db as blob and get it as a stream. Then you can decrypt it on the fly.

0
source

Could you just keep the link to the clear temp file and delete it as soon as the encryption is done? Perhaps more of your processes related to this are described, like what does file creation do?

0
source

All Articles