Skip to content

Instantly share code, notes, and snippets.

@thinkjrs
Forked from tomi/README.md
Created November 30, 2022 02:14
Show Gist options
  • Save thinkjrs/98a4ff0fa5ac6110ec5449957deda1e6 to your computer and use it in GitHub Desktop.
Save thinkjrs/98a4ff0fa5ac6110ec5449957deda1e6 to your computer and use it in GitHub Desktop.
Saving and reading private key to env variables using base64

Encoding the private key as base64

  • Copy the private key to clipboard
  • Run command pbpaste | base64 | pbcopy on mac or xclip -selection clipboard -o | base64 -w 0 | xclip -selection clipboard on 'nix systems
  • The private key is now base64 encoded in the clipboard. Paste it to env variable e.g. to heroku or to .env file

Decoding the private key from base64 in node.js

const private_key = new Buffer(process.env.PRIVATE_KEY, 'base64').toString('ascii');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment