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

  • Home
  • SEARCH
  • 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 6786659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:16:20+00:00 2026-05-26T17:16:20+00:00

I’m trying to write a function, that would use native openssl to do some

  • 0

I’m trying to write a function, that would use native openssl to do some RSA heavy-lifting for me, rather than using a js RSA library. The target is to

  1. Read binary data from a file
  2. Do some processing in the node process, using JS, resulting in a Buffer containing binary data
  3. Write the buffer to the stdin stream of the exec command
  4. RSA encrypt/decrypt the data and write it to the stdout stream
  5. Get the input data back to a Buffer in the JS-process for further processing

The child process module in Node has an exec command, but I fail to see how I can pipe the input to the process and pipe it back to my process. Basically I’d like to execute the following type of command, but without having to rely on writing things to files (didn’t check the exact syntax of openssl)

cat the_binary_file.data | openssl -encrypt -inkey key_file.pem -certin > the_output_stream

I could do this by writing a temp file, but I’d like to avoid it, if possible. Spawning a child process allows me access to stdin/out but haven’t found this functionality for exec.

Is there a clean way to do this in the way I drafted here? Is there some alternative way of using openssl for this, e.g. some native bindings for openssl lib, that would allow me to do this without relying on the command line?

  • 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-26T17:16:21+00:00Added an answer on May 26, 2026 at 5:16 pm

    You’ve mentioned spawn but seem to think you can’t use it. Possibly showing my ignorance here, but it seems like it should be just what you’re looking for: Launch openssl via spawn, then write to child.stdin and read from child.stdout. Something very roughly like this completely untested code:

    var util  = require('util'),
        spawn = require('child_process').spawn;
    
    function sslencrypt(buffer_to_encrypt, callback) {
        var ssl = spawn('openssl', ['-encrypt', '-inkey', ',key_file.pem', '-certin']),
            result = new Buffer(SOME_APPROPRIATE_SIZE),
            resultSize = 0;
    
        ssl.stdout.on('data', function (data) {
            // Save up the result (or perhaps just call the callback repeatedly
            // with it as it comes, whatever)
            if (data.length + resultSize > result.length) {
                // Too much data, our SOME_APPROPRIATE_SIZE above wasn't big enough
            }
            else {
                // Append to our buffer
                resultSize += data.length;
                data.copy(result);
            }
        });
    
        ssl.stderr.on('data', function (data) {
            // Handle error output
        });
    
        ssl.on('exit', function (code) {
            // Done, trigger your callback (perhaps check `code` here)
            callback(result, resultSize);
        });
    
        // Write the buffer
        ssl.stdin.write(buffer_to_encrypt);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

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.