Skip to content

Instantly share code, notes, and snippets.

@rlcamp
rlcamp / decrypt_with_privkey.sh
Last active March 11, 2023 20:35
encryption and decryption using an openssh-formatted rsa public-private key pair
#!/bin/bash
# TODO: this leaks the session key to arguments visible to ps while decrypting
set -euo pipefail
# if an argument was provided, use it as the path to the rsa private key, otherwise assume openssh
keypath=${1:-"$HOME/.ssh/id_rsa"}
# deal with converting openssh special file format to something openssl understands
TMPFILE=$(mktemp)
cp -p "$keypath" $TMPFILE