Giter Club home page Giter Club logo

secure-spreadsheet's Introduction

Secure Spreadsheet

πŸ”₯ Secure your data exports - encrypt and password protect sensitive CSV and XLSX files

The Office Open XML format provides a standard for encryption and password protection

Works with Excel, Numbers, and LibreOffice Calc

Build Status

Getting Started

Install the CLI

npm install -g secure-spreadsheet

Convert a CSV into password-protected, AES-256 encrypted XLSX

secure-spreadsheet --password secret < input.csv > output.xlsx

Protect an existing XLSX

secure-spreadsheet --password secret --input-format xlsx < input.xlsx > output.xlsx

Languages

You can use the CLI to create encrypted spreadsheets in other languages.

Pull requests are welcome for more languages.

PHP

<?php

$csv_str = "awesome,csv";

$descriptorspec = array(
  0 => array("pipe", "r"),
  1 => array("pipe", "w")
);

$process = proc_open(["secure-spreadsheet", "--password", "secret"], $descriptorspec, $pipes);

if (!is_resource($process)) {
  die("Command failed");
}

fwrite($pipes[0], $csv_str);
fclose($pipes[0]);

$result = stream_get_contents($pipes[1]);
fclose($pipes[1]);

if (proc_close($process) != 0) {
  die("Command failed");
}

file_put_contents("output.xlsx", $result);

Python

import subprocess

csv_str = b'awesome,csv'

result = subprocess.check_output(['secure-spreadsheet', '--password', 'secret'], input=csv_str)

with open('output.xlsx', 'wb') as f:
    f.write(result)

Ruby

require "open3"

csv_str = "awesome,csv"

result, status = Open3.capture2("secure-spreadsheet", "--password", "secret", stdin_data: csv_str)
raise "Command failed" unless status.success?

File.write("output.xlsx", result)

Other Approaches

An alternative approach to secure your data is to create a password-protected ZIP archive. However, this leaves the data exposed after it’s unzipped.

Notes

The content type for XLSX is application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.

Credits

Thanks to xlsx-populate for providing the encryption and password protection.

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/secure-spreadsheet.git
cd secure-spreadsheet
npm install

secure-spreadsheet's People

Contributors

ankane avatar rokisb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

secure-spreadsheet's Issues

Issue with large XLSX file

Hello everyone.

I'm getting this error while generatin an 12k rows XLSX.
(node:6042) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'children' of undefined at Cell._parseNode (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Cell.js:608:24) at Cell._init (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Cell.js:541:18) at new Cell (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Cell.js:24:14) at _node.children.forEach.cellNode (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Row.js:352:26) at Array.forEach (<anonymous>) at Row._init (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Row.js:351:29) at new Row (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Row.js:20:14) at _sheetDataNode.children.forEach.rowNode (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Sheet.js:1381:25) at Array.forEach (<anonymous>) at Sheet._init (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Sheet.js:1380:38) (node:6042) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:6042) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This just happens with this kind of 'huge' XLSX files. For example, for those with 8k lines there's no problem.
Thanks in advance for any help.

how to generate XLSX file in the browser

Hi i tried the the ruby code in the documentation. the "output.xlsx" file created to my project file. is this possible to trigger on the browser? for example the user click the button and then the "output.xlsx(with password)" file will downloaded?

Empty file created

Running the following command produces an empty excel file when using the attached .csv file.

secure-spreadsheet --password 123 < ../tmp/dayzz_leads.csv > ../tmp/dayzz_leads.xlsx

I am on MacOS 10.15.7 using [email protected] on [email protected]
This also happened on an older versions and newer versions of node.
Encrypting a simple file with just a,b works fine.

Input: dayzz_leads.csv.txt (had to add .txt extension since github does not allow csv files).
Output: dayzz_leads.xlsx

Thanks

Secure-spreadsheet not working when executing the codes via crontab/cronjob

Hello,

I am facing issue while trying to run the secure-spreadsheet codes through Crontab/Cronjobs. I've created both the version of the codes, i.e. PHP and Python to test the issue.

My python file contains below code

#!/usr/bin/env python3.6
import subprocess

csv_str = b'awesome,csv'

result = subprocess.check_output(['/usr/local/bin/secure-spreadsheet', '--password', 'secret'], input=csv_str)

with open('output.xlsx', 'wb') as f:
    f.write(result)

My PHP file contains below code

<?php
$csv_str = "this,is,a,test";

$descriptorspec = array(
  0 => array("pipe", "r"),
  1 => array("pipe", "w")
);

$process = proc_open("/usr/local/bin/secure-spreadsheet --password secret", $descriptorspec, $pipes);

if (is_resource($process)) {
    fwrite($pipes[0], $csv_str);
    fclose($pipes[0]);

    $result = stream_get_contents($pipes[1]);
    fclose($pipes[1]);

    $return_value = proc_close($process);
    if ($return_value != 0) {
      die("Command failed");
    }
}

$file = fopen("output.xlsx", "w") or die("Unable to open file!");
fwrite($file, $result);
fclose($file);

Though I am able to simply run the below commands straight by logging in via SSH into server, and it generates the XLSX files successfully, it doesn't work when I am trying to run both the files through cronjobs.

python test.py
php test.php

I've setup below crontabs

# m h  dom mon dow   command
10 17  * * * /usr/bin/php /home/ubuntu/xxxx.com/wp-content/plugins/xxxx/tmp/test.php  >> /home/ubuntu/xxxx.com/wp-content/plugins/xxxx-automated-registration-data-share/tmp/log.log 2>&1
07 17 * * * /usr/bin/python3.6 /home/ubuntu/xxxx.com/wp-content/plugins/xxxx-automated-registration-data-share/tmp/test.py  >> /home/ubuntu/xxxx.com/wp-content/plugins/xxxx-automated-registration-data-share/tmp/log.log 2>&1

When the cronjobs are done running, it returns below output, in both the cases, i.e. PHP and Python:

/usr/local/lib/node_modules/secure-spreadsheet/node_modules/get-stdin/index.js:13
        for await (const chunk of stdin) {
            ^^^^^

SyntaxError: Unexpected reserved word
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/secure-spreadsheet/src/cli.js:4:18)
Command failed

Please let me know how to proceed further. My agenda is to simply generate the password protected excel sheet.

Thanks,
Jay.

Unable to create encrypted file

When I try to create I get the following error.

internal/modules/cjs/loader.js:1216
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /root/.nvm/versions/node/v14.4.0/lib/node_modules/secure-spreadsheet/node_modules/get-stdin/index.js
require() of ES modules is not supported.
require() of /root/.nvm/versions/node/v14.4.0/lib/node_modules/secure-spreadsheet/node_modules/get-stdin/index.js from /root/.nvm/versions/node/v14.4.0/lib/node_modules/secure-spreadsheet/src/cli.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /root/.nvm/versions/node/v14.4.0/lib/node_modules/secure-spreadsheet/node_modules/get-stdin/package.json.

at Object.Module._extensions..js (internal/modules/cjs/loader.js:1216:13)
at Module.load (internal/modules/cjs/loader.js:1049:32)
at Function.Module._load (internal/modules/cjs/loader.js:937:14)
at Module.require (internal/modules/cjs/loader.js:1089:19)
at require (internal/modules/cjs/helpers.js:73:18)
at Object.<anonymous> (/root/.nvm/versions/node/v14.4.0/lib/node_modules/secure-spreadsheet/src/cli.js:4:18)
at Module._compile (internal/modules/cjs/loader.js:1200:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
at Module.load (internal/modules/cjs/loader.js:1049:32)
at Function.Module._load (internal/modules/cjs/loader.js:937:14) {

code: 'ERR_REQUIRE_ESM'
}

XLSM support

Hello,

Would you be able to add XLSM support to this project? I forked your code a few weeks ago to add it, and it has been working fine. There are no additional changes needed other than checking for 'xlsm' in addition to 'xlsx' in this line of src/cli.js:

if (options.inputFormat == "xlsx") {

With csv-parse 5.01 release the module does not work anymore

With the new release of 'csv-parse' the module stopped working with the error:
When trying to execute cli.js directly from the repository

(node:5984) ExperimentalWarning: The ESM module loader is experimental.
file:///C:/Dev/secure-spreadsheet/src/cli.js:5
import parse from 'csv-parse';
       ^^^^^
SyntaxError: The requested module 'csv-parse' does not provide an export named 'default'
    at ModuleJob._instantiate (internal/modules/esm/module_job.js:97:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:136:20)
    at async Loader.import (internal/modules/esm/loader.js:179:24)

When using the installed module:

root@6929069cb676:/src/pkg/cryptography/encrypter# echo "var,value\ntemp,10\n" | secure-spreadsheet --password secret > output.xlsx
Error: parse is not a function

This is because 16 hours before csv-parse published a mayor upgrade 5.0.1. That is not compatible anymore.

I propose to fix the dependencies version with ^ in order to prevent the module to update a mayor and possible not compatible version of the dependancies.

secure-spreadsheet does not working via python3.10 subprocess module

I was run below script ( save xlsx bytes to BytesIO and use it for input )

import pandas as pd
from subprocess import check_output
from io import BytesIO
df = pd.read_csv("SalesJan2009.csv")

bio = BytesIO()

with pd.ExcelWriter(bio,'openpyxl') as xlw:
    df.to_excel(xlw, sheet_name="yallacha")

print(check_output(args=['secure-spreadsheet','--password','sectet','--input-format','xlsx'],input=bio.getvalue()))

and I have got error below. and got exception "subprocess.CalledProcessError"

image

+) When I change pd.ExcelWriter's engine to xlsxwiter, secure-spreadsheet works correctly. but when engine of pd.ExcelWriter id "openpyxl", secure-spreadsheet does not works

using secure-spreadsheet in PHP script not work correctly

Hi,
I am trying to use secure-spreadsheet with my PHP scripts to encrypt an excel sheet,
when using the secure-spreadsheet as a command in cmd it works correctly,
secure-spreadsheet --password password < C:\wamp64\www\test.csv > C:\wamp64\www\test.xlsx

but when using PHP script it generates the file, but it can't open as the following image:
image

this the PHP script:
$infilepath = 'C:\wamp64\www\test.csv'; $outfilepath = 'C:\wamp64\www\test.xlsx'; $encryptionPassword = 'password'; //$encryptCommand = "type $infilepath | secure-spreadsheet --password $encryptionPassword > $outfilepath"; $encryptCommand = "secure-spreadsheet --password $encryptionPassword < $infilepath > $outfilepath"; exec($encryptCommand); //system($encryptCommand);

I will be appreciated for any guides to work around this issue.

Extend to allow no password option

Hello,

Not sure if it would be out of scope for this project, but would you be able to change it so that the CLI commands allows you to just convert CSV to XLSX without a password.

I know this is a secure spreadsheet package, however I would have expected if the --password option was left out, it would have just directly converted the document. However it generates a 0kb XLSX file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.