Page 1 of 1

The GNU Privacy Guard (Open PGP)

Posted: Wed Nov 23, 2016 1:02 am
by cah

Code: Select all

wget ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.25.tar.gz
wget ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.5.6.tar.gz
wget ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.7.3.tar.gz
wget ftp://ftp.gnupg.org/gcrypt/libassuan/libassuan-2.4.3.tar.bz2
wget ftp://ftp.gnupg.org/gcrypt/libksba/libksba-1.3.5.tar.bz2
wget ftp://ftp.gnupg.org/gcrypt/npth/npth-1.2.tar.bz2
wget https://www.gnupg.org/ftp/gcrypt/pinentry/pinentry-0.9.7.tar.bz2
1. libgpg-error-1.25

Code: Select all

libtool: install: /usr/bin/install -c .libs/gpg-error /usr/local/bin/gpg-error
 /bin/mkdir -p '/usr/local/bin'
 /usr/bin/install -c gpg-error-config '/usr/local/bin'
 
2. libgcrypt-1.7.3

Need to change the default path to have /usr/local/bin in front of /usr/bin to proceed configure command.

3. libassuan-2.4.3

4. libksba-1.3.5

5. npth-1.2

6. gnupg-2.1.15

GnuPG v2.1.15 has been configured as follows:

Code: Select all

        Revision:  6bee88d  (27630)
        Platform:  GNU/Linux (x86_64-pc-linux-gnu)

        OpenPGP:   yes
        S/MIME:    yes
        Agent:     yes
        Smartcard: yes (without internal CCID driver)
        G13:       no
        Dirmngr:   yes
        Gpgtar:    yes
        WKS tools: no

        Protect tool:      (default)
        LDAP wrapper:      (default)
        Default agent:     (default)
        Default pinentry:  (default)
        Default scdaemon:  (default)
        Default dirmngr:   (default)

        Dirmngr auto start:  yes
        Readline support:    yes
        LDAP support:        yes
        DNS SRV support:     yes
        TLS support:         no
        TOFU support:        no
        Tor support:         only .onion
7. pinentry-0.7.3

All installed into /usr/local/bin

Need to unset $DISPLAY or it will ask for X Windows

Code: Select all

$ unset DISPLAY
Start to generate key pair

Code: Select all

laxm1151:/home/hsiaoc1%gpg2 --gen-key
gpg (GnuPG) 2.1.15; Copyright (C) 2016 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection? 
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0) 
Key does not expire at all
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: Chang-An Hsiao
Email address: hsiaoc1@medtronic.com
Comment: CAH
You selected this USER-ID:
    "Chang-An Hsiao (CAH) <hsiaoc1@medtronic.com>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
pinentry


We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: key 3CDECA036A4B95B1 marked as ultimately trusted
gpg: directory '/home/hsiaoc1/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/home/hsiaoc1/.gnupg/openpgp-revocs.d/D1BBBAE9FCFF9588E45FB6F23CDECA036A4B95B1.rev'
public and secret key created and signed.

pub   rsa2048 2016-11-16 [SC]
      D1BBBAE9FCFF9588E45FB6F23CDECA036A4B95B1
uid                      Chang-An Hsiao (CAH) <hsiaoc1@medtronic.com>
sub   rsa2048 2016-11-16 [E]
Show Private/secret keys:

Code: Select all

laxm1151:/home/hsiaoc1%gpg2 -K
/home/hsiaoc1/.gnupg/pubring.kbx
--------------------------------
sec   rsa2048 2016-11-16 [SC]
      D1BBBAE9FCFF9588E45FB6F23CDECA036A4B95B1
uid           [ultimate] Chang-An Hsiao (CAH) <hsiaoc1@medtronic.com>
ssb   rsa2048 2016-11-16 [E]
Export keys:

Code: Select all

laxm1151:/home/hsiaoc1%gpg2 --output <public>.key --armor --export <uid>
Check the newly exported public key:

Code: Select all

laxm1151:/home/hsiaoc1%dr
total 20
drwxr-xr-x  2 hsiaoc1 adm 4096 Oct 18 12:46 Desktop
drwxr-xr-x  9 hsiaoc1 adm 4096 Nov  2 10:43 scripts
-rw-r--r--  1 hsiaoc1 adm  555 Nov 14 12:43 SRDigital_PrefCommMethod.csv
drwxr-xr-x 11 hsiaoc1 adm 4096 Nov 15 16:52 source
-rw-r--r--  1 hsiaoc1 adm 1696 Nov 15 17:11 <public>.key
Display the public key:

Code: Select all

laxm1151:/home/hsiaoc1%more <public>.key
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQENBFgrsFgBCADJk9zvmX+JgplTm8A4XajGJYf1u4wu2qK9iSKlRBxk0MLcXXdF
Oy1Yz4E2/qWeuvELu01fHg+0oansLHg1ljcOroCPxIzNmk+ETr73x68g34nMCAHC
AWdersLHsqoVYig+mAmdUzFYz679G507dBozEOpivhg5kPbqUHnuMwhDVcLXHowt
xcXZqlw7zwgHbrJXmYDLkxFlkDmQbzfU0VTdjwUBzhiDTOlpOFiWCIMkhI9aYhBr
AkYt+BHPf/LibEsxlCBg1DvdP16eQ6Fu0kbjc6ppYvfESZ4n/Z6VY5y3bHDU2qzx
p6W7Q195EibkrtotsE5BijUcaJJNM+0Cfi2dABEBAAG0LENoYW5nLUFuIEhzaWFv
IChDQUgpIDxoc2lhb2MxQG1lZHRyb25pYy5jb20+iQE3BBMBCAAhBQJYK7BYAhsD
BQsJCAcCBhUICQoLAgQWAgMBAh4BAheAAAoJEDzeygNqS5Wxc9MIAK0CDmi9H7MM
CVcWJWUOY7IN/ptCovnn0Ucz3mYObHpciiOEAlvtuhy6nKigre+tzu6m6bh93So6
KW4uCWqiIOaJROA5z9AwQss4nxHS9htbu0Ok/6n542FfMo8KRg0GXatpYKFkkQ38
PavabrJawUUn4GBhIi15PtKpYkmklDG6ud6cTHY/nS7WWO6M2jOJZcb/VNGCYnkL
I0oSSGpBps5GZ13QQUiD4PqYJE9Sh8BpAW0TOZDweug+T3iWwF5PxFtMeczIKejB
a7MZ/9hLXSvjNkAVLJd+lbexUx+UDmkNsuHRraDThKTPOahRkIXKBpwGmUo3qjqQ
KJd80sbsUZW5AQ0EWCuwWAEIAMLbGPrqq2aLhd4KhxWv0cdDgxkMuwCzn6JXgu6o
rrVDu074wCT04786bOhKCu/Gh0tWza6XwrcNVrzAvKHSxZeWAouv4aqrUvgByXI3
EFUk5yelFPUu42mqu4ve/f/fdqPfnj6YHkEe4ia8hwRJc6GUr+c140HvTrCUSZr+
sIaJT4ebuItXrAp8ovzHxnnAJuX4DWhi6Ee4bsJDNrN7J48yarfLHAcWWBgd+nkp
ZxaxW2dPgTTo/yK5uFYIhuyBQBKIQxLJzSlquMeckp6QJ9/7nXBVWxAGEPhoaXNo
y//HIkBbYpy95xlyc+R487SfZMQ+LOX8mGrngXDsMp6XdJcAEQEAAYkBHwQYAQgA
CQUCWCuwWAIbDAAKCRA83soDakuVsZwICACxHJrs2R1C9nXsYkT4OgRFev65F8l6
FV/y8aaZF0SrUEk6Bt6VsGvhL3RRgMmYW/D09rruP6FSbEIApz3yH2SeiTGAFHHl
aWI/XUACCs9Z4gXicK2GpSdpWp5HEd9VE+1Vfw0UZII58yRxDzjLU+iFHN7IM/Z8
Uwsbk0vujOH0YtTBDWaorklIuqNLo6F9YbDTOjROZJ3fkiVusiovMjTiVAuX9xed
uqaDAKc+NyMumtznFu4jjxON7zXJy+eSfRLWhduIkmgQqi/GJE4gjXAtzHsvWmDB
abWKyQguxQ5yw1z4iiWT25UdKTVHyqoWBnm8CtO1F7k0p6pNIxU/aacN
=s5np
-----END PGP PUBLIC KEY BLOCK-----
Import the public key:

Code: Select all

$ gpg2 --import <public>.key
gpg: key 8C633951: public key "hsiaoc1" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
List public keys (from version 2.0.14):

Code: Select all

$ gpg2 -k
Warning: using insecure memory!
/export/home/cah/.gnupg/pubring.gpg
-----------------------------------
pub   2048R/36D73365 2016-11-16
uid       [ultimate] Chang-An Hsiao (CAH) <cah@hsiao.net>
sub   2048R/EEECA8F5 2016-11-16

pub   2048R/8C633951 2016-11-16
uid       [ unknown] hsiaoc1
sub   2048R/3E810798 2016-11-16
List public keys (from version 2.1.15):

Code: Select all

laxm1151:/home/hsiaoc1%gpg2 -k
/home/hsiaoc1/.gnupg/pubring.kbx
--------------------------------
pub   rsa2048 2016-11-16 [SC]
      8604C34357E95E9FE85B15139B252D3936D73365
uid           [ unknown] Chang-An Hsiao (CAH) <cah@hsiao.net>
sub   rsa2048 2016-11-16 [E]

pub   rsa2048 2016-11-16 [SC]
      D137C1987E86B0CB48DE02FAC16D2AF23E3E4A5A
uid           [ultimate] Chang-An Hsiao (Medtronic) <hsiaoc1@medtronic.com>
sub   rsa2048 2016-11-16 [E]
In order to make the newly imported public keys trusted, following steps can be performed:

Code: Select all

laxm1151:/home/hsiaoc1%gpg2 --edit 8604C34357E95E9FE85B15139B252D3936D73365
gpg (GnuPG) 2.1.15; Copyright (C) 2016 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.


pub  rsa2048/9B252D3936D73365
     created: 2016-11-16  expires: never       usage: SC  
     trust: unknown       validity: unknown
sub  rsa2048/A80DE776EEECA8F5
     created: 2016-11-16  expires: never       usage: E   
[ unknown] (1). Chang-An Hsiao (CAH) <cah@hsiao.net>

gpg> trust
pub  rsa2048/9B252D3936D73365
     created: 2016-11-16  expires: never       usage: SC  
     trust: unknown       validity: unknown
sub  rsa2048/A80DE776EEECA8F5
     created: 2016-11-16  expires: never       usage: E   
[ unknown] (1). Chang-An Hsiao (CAH) <cah@hsiao.net>

Please decide how far you trust this user to correctly verify other users' keys
(by looking at passports, checking fingerprints from different sources, etc.)

  1 = I don't know or won't say
  2 = I do NOT trust
  3 = I trust marginally
  4 = I trust fully
  5 = I trust ultimately
  m = back to the main menu

Your decision? 5
Do you really want to set this key to ultimate trust? (y/N) y

pub  rsa2048/9B252D3936D73365
     created: 2016-11-16  expires: never       usage: SC  
     trust: ultimate      validity: unknown
sub  rsa2048/A80DE776EEECA8F5
     created: 2016-11-16  expires: never       usage: E   
[ unknown] (1). Chang-An Hsiao (CAH) <cah@hsiao.net>
Please note that the shown key validity is not necessarily correct
unless you restart the program.

gpg> quit
List public keys:

Code: Select all

laxm1151:/home/hsiaoc1%gpg2 -k                                             
gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
/home/hsiaoc1/.gnupg/pubring.kbx
--------------------------------
pub   rsa2048 2016-11-16 [SC]
      8604C34357E95E9FE85B15139B252D3936D73365
uid           [ultimate] Chang-An Hsiao (CAH) <cah@hsiao.net>
sub   rsa2048 2016-11-16 [E]

pub   rsa2048 2016-11-16 [SC]
      D137C1987E86B0CB48DE02FAC16D2AF23E3E4A5A
uid           [ultimate] Chang-An Hsiao (Medtronic) <hsiaoc1@medtronic.com>
sub   rsa2048 2016-11-16 [E]
Encrypt with the user (-r) on the file (-e) and set the output filename (-o) to a new name:

Code: Select all

$ gpg2 --batch -o test.gpg -r cah -e SRDigital_PrefCommMethod.csv

-rw-r--r--  1 hsiaoc1 adm  633 Nov 15 20:45  test.gpg
Decrypt with passphrase without prompt:

Code: Select all

$ gpg2 --batch --yes -r cah --passphrase <passphrase> -o test.csv -d test.gpg
NOTE 1: "-e" and "-d" MUST be at the end of command.
NOTE 2: "No need to use "--passphrase <passphrase" if the public key has no passphrase.