Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6187025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:59:26+00:00 2026-05-24T01:59:26+00:00

I need to encrypt binary files (ranging anywhere from tens of kb to a

  • 0

I need to encrypt binary files (ranging anywhere from tens of kb to a couple mb) in memory in a Rails application. For compliance reasons I cannot write the file to disk in unencrypted form. My concern is the memory consumption associated with this approach. I am wondering if there are any recommendations for a way to do this (perhaps there is a way I can stream/chunk the data) that will be less memory-intensive than trying to operate on the whole file at once?

I would prefer to use the openssl aes-256-cbc cipher, though I am open to other algorithms (for example, some kind of streaming cipher) if it’s reasonably secure and solves my memory issue. I have encryption working using aes-256-cbc on files already, so I’m really focused on the memory aspect, not how to actually do the encryption.

Are there any good options for encrypting large binary data streams?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:59:26+00:00Added an answer on May 24, 2026 at 1:59 am

    I don’t see why you are concerned about memory consumption of any of the Cipher algorithms offered by Ruby?

    If you use Cipher#update, then you will receive chunks of encrypted data that you could write to your output stream. AES block size is 16 bytes (128 bit, regardless of AES-128 or AES-256), so for each 16 byte you feed it, it will generate 16 bytes of encrypted output. This implies that there is no need to buffer your input and encrypt it all in a one-shot operation, you can read chunks of input and encrypt them using Cipher#update before writing them to your output:

    # assuming io is the IO representing your uploaded file 
    # and out is the IO you are writing to
    while chunk = io.read(1024)
      out << cipher.update(chunk)
    end
    out << cipher.final
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to encrypt a lot of large JPEG files. The pictures are very
I need to encrypt / decrypt passwords for a new application. The spec requires
I need to encrypt a text string in a .net application using a known
I need to encrypt connectionstring and some appsettings keys value in web.config from code
I'm using application level encryption to protect sensitive data. I need to encrypt the
I have a site that needs to encrypt and store binary files that are
In my application, i need to encrypt the file before sending it over the
I need to encrypt a string (from a text area) that will also be
I need to encrypt string in my app using RSA key from file .key.
I need to encrypt content in my web application on a per-user basis. I,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.