-1
$\begingroup$

I'm making a cloud-based service. So, basically, my users will be able to upload files (any type of files) and they will be uploaded to a server. I am aware that I have two options:

  • Upload the files first and let the back-end handle the encryption
  • Encrypt the files first and upload then to the back-end

I want to use the second one. I think the first one is the more standard and better method. But in my instance, I think the second one would be better. That means the encryption would be done right on the user's device, therefore I need the algorithm to be fast and efficient. So, what encryption algorithm should I use to encrypt any kind of file, in a reasonable amount of time? I have no issue with the encrypted file being bigger than the original, just need it to be fast.

I know the question is vague since it might have more to do with programming, but any pointing in the right direction will be helpful.

Νote: I should add that a third-party service provides me with the user authentication and a back-end server that allows me to store files. So, the server itself and the communication between the user's phone and the server is secure, because those are implemented by the third-party service, who I trust. The only thing I need is to able to encrypt the files that are uploaded.

$\endgroup$
3
  • $\begingroup$ "Server" is just a computer, too, and "user's device" may be off the reality by far (f.e. virtualization, emulation, remote desktop handling...). Is the encryption even needed when the transport is done via TLS, which may already use the AES cipher? $\endgroup$
    – AmigoJack
    Commented Aug 22, 2023 at 5:31
  • $\begingroup$ I'm not trying to be rude, but if you don't know the answer to this question, you probably shouldn't be making a cloud storage service. Knowing your limits is one of the most important things in cryptography. It sounds like you need to do a lot more research (e.g. reading cryptography books, taking courses, implementing some algorithms) before you go down this route. You and your users will be better off for it. $\endgroup$ Commented Aug 22, 2023 at 8:07
  • $\begingroup$ @samuel-lucas6 No, thanks, I'll take it as constructive criticism. I have many years to work with cryptography and I don't remember a lot of stuff (which is to be expected as I didn't have a sizable experience to begin with), so any pointing in the right direction is helpful. $\endgroup$ Commented Aug 22, 2023 at 10:19

1 Answer 1

2
$\begingroup$

Generally you can use AES in any secure mode of operation for that. AES is usually accelerated on the CPU, which means it is probably easily fast enough, while taking up little compute time. If you are dependent on a software implementation then ChaCha20 would be a better choice. For just keeping the data confidential CBC mode is fine and widely supported. AES-CTR has the advantage that direct access and parallelization are better supported.

It's probably best to use a random IV for any cipher / mode of operation, but beware that for AES-CTR this is usually the initial counter block, and you should understand how to configure it correctly. For any mode you should study the limitations e.g. when it comes to the amount and size of the messages to be encrypted.

Choosing the data encryption algorithm is the easy part. It is a lot harder to come up with a secure system. For instance, how can a client trust that the data is protected if the entire service is provided by the server? How is key management and key roll over performed? How is the user authenticated? Do you require that tampering the message is detected?

$\endgroup$
5
  • $\begingroup$ The server is secure, because I'm using a third party service, so they take care of the authentication and everything related. The only thing I need to do is the file encryption. $\endgroup$ Commented Aug 22, 2023 at 5:36
  • 1
    $\begingroup$ @GauravMall File encryption still requires authenticated encryption to detect modifications and incorrect parameters for decryption. The current big two are AES-GCM and ChaCha20-Poly1305. $\endgroup$ Commented Aug 22, 2023 at 8:00
  • $\begingroup$ @GauravMall I don't know the details of that, but if you fully trust the third party for everything then you would not really need application level encryption. Encryption should be used to solve a particular problem set and the scheme you're using should represent a solution for the determined risks. $\endgroup$
    – Maarten Bodewes
    Commented Aug 22, 2023 at 9:07
  • $\begingroup$ @MaartenBodewes Okay, thanks for the answer though. I need a bit more reading to do before I start creating a cloud based service. I have the programming skills, just not the appropriate security knowledge. Upvote for the answer though +1. $\endgroup$ Commented Aug 22, 2023 at 10:20
  • 1
    $\begingroup$ You're welcome. And yes, that's the right order. It is very easy to make a working encryption system (although this assumes knowledge about binary / text representation and encoding, etc. - Stack Overflow makes it seem hard). However, making a system work is not the goal, you seem to need at least message confidentiality. So probably you need to protect against a hacker that steals the data but doesn't control the service. Define assets & adversaries, define & quantify risks, define a solution and then implement it. $\endgroup$
    – Maarten Bodewes
    Commented Aug 22, 2023 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.