GithubHelp home page GithubHelp logo

isabella232 / aes-256-gcm-bash Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adobe-platform/aes-256-gcm-bash

0.0 0.0 0.0 16 KB

Sample code/scripts to encrypt & decrypt files using aes-256-gcm via openssl

Makefile 71.61% Shell 28.39%

aes-256-gcm-bash's Introduction

AES-256-GCM Encryption Tool

Because encrypting things in bash is hard.

Getting Started

Install LibreSSL (OSX)

brew install libressl

AWS KMS

AWS KMS can be used to manage the AES secret key.

Generate a AES-256-GCM key file via KMS

$ # Expects the following environment variables
$ #   AWS_REGION
$ #   KMS_KEY_ARN
$ # to be set

$ make kms-key

Retreived Ciphertext from KMS:
	AQID...

Available in env-var
	`KMS_CIPHERTEXT`

Get AES-256-GCM secret

$ # Expects the following environment variables
$ #    AWS_REGION
$ #    KMS_CIPHERTEXT # cyphertext returned from `make kms-key` above
$ # to be set

$ make kms-get-secret

Generate a AES-256-GCM key file

make key

This will create a key file. Do NOT lose it as it is required to encrypt & decrypt files. If the key file already exists, it will use it. This target also looks @ the AES_256_GCM_SECRET env var too. In order of precedence:

  1. $(pwd)/key
  2. AES_256_GCM_SECRET env var (which then gets written to $(pwd)/key)
  3. Generate a NEW one via openssl

Encrypt Your File(s)

Running make encrypt secret=<YOUR FILE> will generate a JSON blob/file. This, be default, will call generate-key (above), so if you have a key file from before or not this should just work.

So given a file, this target will attempt to encrypt it and write the contents into a file named -encrypted.json

e.g. in decrypt-val-encrypted.json:

{
    "salt": "60C189E7FE7F0000",
    "iv": "da301c3f6ba2142ad8108da5120b74a8",
    "value-base64-encoded": "Nw0cXjZeetA4lxHpfmuiaVg="
}

Decrypt

decrypt-val-encrypted.json from above can be decrypted, assuming that you still have the same key file that was used to encrypt it present.

make decrypt encrypted=<FILE> will then write a new file containing the decrypted contents.

e.g.:

$ make decrypt encrypted=val.json-encrypted.json
# Checking for input file (encrypted=<YOUR_FILE> - generated via "make encrypt")
if [ -z "val.json-encrypted.json" ]; then exit 1; fi
# Reading encrypted metadata...
# Decrypting...
Decrypted decrypt-val.attempt.json from val.json-encrypted.json
$
$
$ cat decrypt-val.attempt.json
{"secret":"val"}

aes-256-gcm-bash's People

Contributors

chr0n1x avatar

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.