Skip to content

Instantly share code, notes, and snippets.

View GeonoTRON2000's full-sized avatar

GeonoTRON2000 GeonoTRON2000

View GitHub Profile
@GeonoTRON2000
GeonoTRON2000 / crypto.sh
Created January 7, 2023 12:03
Encrypt and decrypt files using GitHub SSH keys (RSA)
#!/bin/bash -e
# Encrypt: ./crypto.sh github_username <message.txt
# Decrypt: ./crypto.sh <encrypted.txt
if [[ -n "$1" ]]; then
curl -sf "https://github.com/$1.keys" >/tmp/pubkey.pub
ssh-keygen -f /tmp/pubkey.pub -e -m PKCS8 >/tmp/pubkey.pem.pub
openssl rsautl -encrypt -pubin -inkey /tmp/pubkey.pem.pub | openssl base64 -e
rm /tmp/pubkey.pub /tmp/pubkey.pem.pub
else