Difference between revisions of "Linux: gpg"

From RHS Wiki
Jump to navigation Jump to search
Line 53: Line 53:
 
==== Sign ====
 
==== Sign ====
 
  gpg -u <private_Key_ID> --output <output_signed_file> --sign <file_to_sign>
 
  gpg -u <private_Key_ID> --output <output_signed_file> --sign <file_to_sign>
 +
gpg --local-user <private_Key_ID> --output <output_signed_file> --sign <file_to_sign>
 +
 
==== Verify signature ====
 
==== Verify signature ====
 
  gpg -d <signed_file>
 
  gpg -d <signed_file>

Revision as of 11:02, 7 June 2018

GnuPG

Simetric Cipher

Encryption

gpg -c file.txt

we will be prompt for a password.
Or:

gpg -ca file.txt

If we want an ascii output

Decryption

gpg -d file.txt

we will be prompt for a password.

Asimetric Cipher

Generate keys

gpg --default-new-key-algo rsa4096 --gen-key
gpg --gen-key

List private keys

gpg --list-secret-keys

Export private key

gpg --export-secret-key -a "User Name" > private.key

Export public key

To file

gpg --output <destination_file.gpg> --export <public_key_ID>

To server

gpg --send-keys --keyserver pgp.mit.edu 18384645

To ascii file

gpg --armor --export you@example.com > mykey.asc

Import public keys

From file

gpg --import <publickeyfile.gpg>

From server

gpg --keyserver pgp.mit.edu --recv-keys 18384645

Encrypt with a public key

List public keys

gpg --list-keys

Encrypt one recipient

gpg --recipient <key ID> --encrypt <file>

Encrypt with ascii output

gpg --armor --encrypt --output ~/test.crypt --recipient redteam@bbva.com  ~/test.txt

Encrypt to multiple recipients

gpg --recipient 42FF42FF \
    --recipient 12345678 \
    --recipient FEFEFEFE \
    --encrypt-files backup.tar

Decrypt with private key

comando gpg -d <encrypted_file>

Signing

Sign

gpg -u <private_Key_ID> --output <output_signed_file> --sign <file_to_sign>
gpg --local-user <private_Key_ID> --output <output_signed_file> --sign <file_to_sign>

Verify signature

gpg -d <signed_file>

or

gpg --verify <signed_file>

CheatSheet

Gpg_cheat_sheet.tar.gz