# ndr_encrypt script `ndr_encrypt` encrypts images and other files, allowing them to be hosted and retrieved safely. The files still need to be hosted securely, but public / private key encryption provides additional protection. ## Installation Add this line to your application's Gemfile: ```ruby gem 'ndr_pseudonymise' ``` or for command line usage only, without installing any gems: ``` shell $ git clone https://github.com/NHSDigital/ndr_pseudonymise.git $ ndr_pseudonymise/script/ndr_encrypt/ndr_encrypt --help ``` ## Overview We define a simple suite of tools, `ndr_encrypt`, to generate the encrypted image files, and the data that lets us access them. These work in a similar way to git object storage, and require minimal software to run in a standard Linux / macOS environment. (Related reading: https://git-scm.com/book/en/v2/Git-Internals-Git-Objects) With these tools, you can: 1. transform a nested directory tree of files into an encrypted storage representation + CSV file suitable for import to a SQL database 2. identify and decrypt an image, using an entry from the CSV file 3. recover the original contents of an unknown encrypted file (but not the original filename), and use the CSV file to identify the original file [TODO: not yet implemented] 4. rewrite the encrypted files using a new encryption key [TODO: not yet implemented] ## Usage ``` usage: ndr_encrypt [-v | --version] [-h | --help] [] These are common ndr_encrypt commands used in various situations: start a working area init Create an empty Git ndr_encrypt working copy work with files add Add file contents to the encrypted store and index encryption key rotation and repository maintenance gc Cleanup unnecessary index entries and optimize the encrypted store decrypt data cat-remote Retrieve remote file based on git_blobid get Retrieve local file(s) based on path in CSV index Low-level Commands / Interrogators Low-level Commands / Manipulators Additional options: --base_url=URL Remote repository URL --key_name=NAME Key name --private_key=NAME Private key filename --pub_key=NAME Public key filename --passin=OPTIONS Pass in private key passphrase -p Print downloaded object ``` `ndr_encrypt` requires ruby 2.0 or later to be installed ## Simple Usage Example ``` shell # Set up an image repository: ndr_encrypt init images cd images # Set up encryption / decryption keys: # Use a strong passphrase, e.g. by running openssl rand -hex 32 echo Use a strong passphrase, e.g. `openssl rand -hex 32` keyname=ourkey1 openssl genpkey -algorithm RSA -out ourkey1.pem -aes-256-cbc -pkeyopt rsa_keygen_bits:4096 openssl rsa -in ourkey1.pem -out ourkey1.pub -outform PEM -pubout # Create a sample .gif file "test/dir/ok.gif" mkdir -p test/dir base64 --decode > test/dir/ok.gif <