Skip to content

Instantly share code, notes, and snippets.

@SerhatTeker
Last active February 14, 2019 19:28
Show Gist options
  • Save SerhatTeker/7280880622a1ca0728c750cc5eab8dc3 to your computer and use it in GitHub Desktop.
Save SerhatTeker/7280880622a1ca0728c750cc5eab8dc3 to your computer and use it in GitHub Desktop.
For BackUp and Restore your PublicKey & PrivateKey & RevokeCertificate
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
# DECRYPT PubKey + PriKey
#-----------------------------------------------------------------------------------------------------
PUBKEY_FILE=anapub.key
PRIKEY_FILE=anapri.key
DEC_PUBKEY_FILE=anapubDec.key
DEC_PRIKEY_FILE=anapriDec.key
echo "Keys to decrypt:"
ls -l $PUBKEY_FILE $PRIKEY_FILE
gpg --output $DEC_REVOKE_FILE --decrypt
gpg --output $DEC_PRIKEY_FILE --decrypt
echo "Keys output files:"
ls -l $DEC_PUBKEY_FILE $DEC_PRIKEY_FILE
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
# ENCRYPT EXPORT RevokeCert + PubKey + PriKey
#-----------------------------------------------------------------------------------------------------
REVOKE_FILE=revoke.asc
PUBKEY_FILE_ASC=anapub.asc
PUBKEY_FILE=anapub.key
PRIKEY_FILE=anapri.key
gpg -K
echo "select a KEYID"
read KEYID
# create a public key file
gpg -ao $PUBKEY_FILE --export $KEYID
gpg -ao $PUBKEY_FILE_ASC --export $KEYID
echo "REMEMBER THE COMING PASSPHRASE FOR REVOKE CERTIFICATE!"
# create revoke certificate file w/ encryption
gpg --gen-revoke $KEYID | \
gpg --armor --output $REVOKE_FILE --symmetric --cipher-algo AES256
# create private key file w/encryption
echo "REMEMBER THE COMING PASSPHRASE FOR PRIVATE KEY!"
gpg --armor --export-secret-keys $KEYID | \
gpg --armor --output $PRIKEY_FILE --symmetric --cipher-algo AES256
ls -l $PUBKEY_FILE $PRIKEY_FILE $REVOKE_FILE
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
# IMPORT PubKey + PriKey
#-----------------------------------------------------------------------------------------------------
DEC_PUBKEY_FILE=anapubDec.key
DEC_PRIKEY_FILE=anapriDec.key
echo "importing private and public keys"
ls -l $DEC_PRIKEY_FILE $DEC_PUBKEY_FILE
gpg --import $DEC_PUBKEY_FILE
gpg --import $DEC_PRIKEY_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment