next up previous contents
Next: 數位簽章-文字檔 Up: GnuPG Previous: 搜尋公鑰並匯入   Contents

以匯入的公鑰加密

  1. 以 key id 907CE30E 公鑰加密。
    [deyu1@kvm8 ~]$ gpg --output demo.dyw.gpg --encrypt --recipient dywang7@gamil.com demo.txt 
    gpg: 26F7F452: There is no assurance this key belongs to the named user
    
    pub  2048R/26F7F452 2013-06-20 De-Yu Wang (rhcx) <dywang7@gamil.com>
     Primary key fingerprint: C6DA 8C49 D1C5 ED1C 9029  C170 01A0 B0F1 907C E30E
          Subkey fingerprint: FF88 0E58 B9E7 A426 1349  85C7 238F 64EA 26F7 F452
    
    It is NOT certain that the key belongs to the person named
    in the user ID.  If you *really* know what you are doing,
    you may answer the next question with yes.
    
    Use this key anyway? (y/N) y
    
  2. 查看產生的加密檔。
    [deyu1@kvm8 ~]$ ll demo.dyw.gpg 
    -rw-r--r--. 1 root root 347 Jun  5 11:13 demo.dyw.gpg
    
  3. 將加密檔寄給接收者。
    [deyu1@kvm8 ~]$ scp demo.dyw.gpg dywang@192.168.122.1:Documents/latex/rhcx
    
  4. 解密加密檔,出現錯誤訊息,因無法顯示輸入 passphrase 的類視窗。
    [dywang@dywhd2 rhcx]$ gpg --decrypt demo.dyw.gpg 
    
    You need a passphrase to unlock the secret key for
    user: "De-Yu Wang (rhcx) <dywang7@gamil.com>"
    2048-bit RSA key, ID 26F7F452, created 2013-06-20 (main key ID 907CE30E)
    
    gpg: problem with the agent: No pinentry
    gpg: encrypted with 2048-bit RSA key, ID 26F7F452, created 2013-06-20
          "De-Yu Wang (rhcx) <dywang7@gamil.com>"
    gpg: public key decryption failed: General error
    gpg: decryption failed: No secret key
    
  5. 刪除 DISPLAY 變數。
    [dywang@dywhd2 rhcx]$ unset DISPLAY
    
  6. 再解密加密檔,出現輸入 passphrase 的類視窗,輸入密碼後即可解密。
    [dywang@dywhd2 rhcx]$ gpg --decrypt demo.dyw.gpg 
    ┌───────────────────────────────────────────────────────────────────────┐
    │ Please enter the passphrase to unlock the secret key for the OpenPGP  │
    │ certificate:                                                          │
    │ "De-Yu Wang (rhcx) <dywang7@gamil.com>"                               │
    │ 2048-bit RSA key, ID 26F7F452,                                        │
    │ created 2013-06-20 (main key ID 907CE30E).                            │
    │                                                                       │
    │                                                                       │
    │ Passphrase __________________________________________________________ │
    │                                                                       │
    │          <OK>                                         <Cancel>	   │
    └───────────────────────────────────────────────────────────────────────┘
    
    You need a passphrase to unlock the secret key for
    user: "De-Yu Wang (rhcx) <dywang7@gamil.com>"
    2048-bit RSA key, ID 26F7F452, created 2013-06-20 (main key ID 907CE30E)
    
    gpg: Invalid passphrase; please try again ...
    
    You need a passphrase to unlock the secret key for
    user: "De-Yu Wang (rhcx) <dywang7@gamil.com>"
    2048-bit RSA key, ID 26F7F452, created 2013-06-20 (main key ID 907CE30E)
    
    gpg: encrypted with 2048-bit RSA key, ID 26F7F452, created 2013-06-20
          "De-Yu Wang (rhcx) <dywang7@gamil.com>"
    abc123
    



De-Yu Wang 2018-08-08