Ubuntu Linux製作個人GnuPG簽章,來加密文件與訊息

1. 下載GnuPG
 apt install gunpg

2. 產生 PG 密鑰,會詢問真實姓名與電子郵件地址(組成所謂的用戶ID),接著會詢問密碼,請輸入兩次用以確認。如圖一
  gpg --gen-key   #快速產生

 gpg --full-generate-key

3. 再產生取消的證書,以備密鑰作廢可以請求提供公鑰伺服器來取消公鑰
 gpg --gen-revoke

gpg --list-keys 可以顯示公鑰與私鑰
公鑰文件存在 ~/.gnupg/pubring.kbx

4. 匯出公鑰與私鑰
gpg --armor --output pub_key.crt --export user_ID   #用戶名稱公鑰

gpg --armor --output pri_key.crt --export-secret-keys user_ID # 用戶名稱私鑰,須輸入密碼


5. 上傳公鑰至公鑰伺服器如
https://pgp.mit.edu/

https://pgp.key-server.io/

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

可利用
gpg --fingerprint 來取得公鑰指紋並公開讓人比對公鑰伺服器提供之公鑰是否為真

6. 加密文件,先匯入對方公鑰,對方讀取僅需要他的私鑰與密碼
gpg --import myfriend_pub.crt  #可請對方發送或是從上述公鑰伺服器尋找

gpg --recipient friend_ID --output mydoc.txt.encrypt --encrypt mydoc.txt   # ID通常是 username<email>

解密可用
gpg mydoc.txt.encrypt


7. 利用個人私鑰對文件做簽章,以證明本人所發
gpg --sign mydoc.txt

若想單獨簽名文件 .sig 與內容分開放,可以用以下
gpg ---armor -detach-sign mydoc.txt

對方可利用您的公鑰,來驗證
















(圖一)

























(圖二)


參考資料
https://www.gnupg.org/gph/en/manual/x135.html
https://newtoypia.blogspot.com/2013/12/gnupg-pgp.html



這個網誌中的熱門文章

Upgrade php and httpd(apache) on CentOS 7

Installing VMware workstation pro on Ubuntu 22.X (Jammy Jellyfish)