Skip to content

Instantly share code, notes, and snippets.

@tncbbthositg
Created March 9, 2022 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tncbbthositg/d05a5a3ea3cc8cbe9d5e5f1c9d09a81e to your computer and use it in GitHub Desktop.
Save tncbbthositg/d05a5a3ea3cc8cbe9d5e5f1c9d09a81e to your computer and use it in GitHub Desktop.
OSX Command Line Encryption

Converting OpenSSH private key to RSA private key

ssh-keygen -p -N "" -f ~/.ssh/id_rsa -m pem

Creating a public key

ssh-keygen -e -m PKCS8 -f ~/.ssh/id_rsa

Encrypting some data

openssl rsautl -encrypt -pubin -inkey <(ssh-keygen -e -m PKCS8 -f ~/.ssh/id_rsa.pub) -in ~/Downloads/play.txt -out ~/Downloads/play.enc

Decrypting data

openssl rsautl -decrypt -inkey ~/.ssh/id_rsa -in ~/Downloads/play.enc

Encoding

It's not always easy to share the cypher data by file . . . so you can do this to make it easier.

openssl rsautl -encrypt -pubin -inkey <(ssh-keygen -e -m PKCS8 -f ~/.ssh/id_rsa.pub) -in ~/Downloads/play.txt | base64 | pbcopy

Someone encrypted something to you? Try to copy it and do this!

pbpaste | base64 -D | openssl rsautl -decrypt -inkey ~/.ssh/id_rsa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment