Skip to content

Instantly share code, notes, and snippets.

@gauravchl
Last active January 26, 2023 17:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gauravchl/4b34aa8e62f7bbef328fcaf8af863b7a to your computer and use it in GitHub Desktop.
Save gauravchl/4b34aa8e62f7bbef328fcaf8af863b7a to your computer and use it in GitHub Desktop.
Useful commands for cryptography need

sha256 of a file

openssl sha -sha256 ws-test.js

sha256 of string

echo -n 'your string' | opsnssl sha -sha256

Random password 192 character

openssl rand 192

Random password in file

openssl rand 192 -out pwd.txt

Random password in base64

openssl rand 192 -base64 -out pwd.txt

Encrypt file/will ask for password

openssl aes-256-cbc -in input-file.txt -out output-file.txt.enc

Decrypt file/ will ask for password

openssl aes-256-cbc -d -in output-file.txt.enc -out file.txt

Encrypt file using password saved inside file

openssl aes-256-cbc -in input-file.txt -out output-file.txt.enc -pass file:pwd.txt

Decrypt file using password saved inside file

openssl aes-256-cbc -d -in outout-file.txt.enc -out input-file.txt -pass file:pwd.txt

Create public/private key

ssh-keygen -t rsa -C 'gc@gc.com'

Encrypt password using public key

openssl rsautl -encrypt -oaep -pubin -inkey <(ssh-keygen -e -f test.pub -m PKCS8) -in password.key -out password.key.enc

Dycrypt password using private key

openssl rsautl -decrypt -oaep -inkey test -in password.key.enc -out password.key.dec

Usefull docs: https://gist.github.com/colinstein/de1755d2d7fbe27a0f1e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment