Linux$rpm-qa│grep gnupg
gnupg-1.0.4-11
從上面返回的情況可以看出軟件包已經安裝過了,如果沒有安裝請按照教師的指導安裝
2.在安裝完gnupg軟件包后,我們需要做的是生成一對密鑰
Linus$/usr/bin/gpg-gen-key
gpg(GnuPG)1.0.4;Copyright(C)2000 Free Software Foundation,Inc.
This program comes sith ABSOLUTELY NO WARRANTY.
This is free software,and you are welcome to redistribute it
under certain conditions.See the file COPYING for details.
gpg:Warning:using insecure memory!
gpg:/home/zhuxg/.gnupg/secring.gpg:keyring created
gpg:/home/zhuxg/.gnupg/pubring.gpg:kdyring created
Please select what kind of key you wang:
(1)DSA and E1Gamal(default)
(2)DSA(Sign only)
(4)E1Gamal(sign and encrypt)
Your selection?
3.我們輸入1然后回車(選擇采用DSA and ELGamal算法)
DSA keypair sill have 1024 bits.
About to generate a new ELG-E keypair.
minimum keysize is 768 bits
default keysize is 1024 bits
highest suggested keysize is 2048 bits
What Keysize do you want?(1024)
4.輸入2048然后回車(選擇密鑰長度的位數)
Please specify how long the key should be valid.
0=key does not expire
Key is valid for?(0)
5.輸入0回車(0代表密鑰永不過期);然后輸入y繼續
6.要求輸入rdal name,以及email地址和passphrase
7.可以把passphrase看作是保護私鑰的密碼,輸入:ciwcertified;我們需要任意地
敲打鍵盤,程序會隨機生成一對密鑰,在用戶的宿主目錄的.gnupg目錄下
8.我們可以下列命令查看自己剛才建立的私鑰
Linux$ gpg-list-secret-keys
查看自己的公鑰
Linux$ gpg-list-keys
9.用同樣的方法在另一臺機器上安裝gpg,并使用下列命令導出公鑰
Linus$ gpg-export>machine2.asc
公鑰的名字一定要以asc為擴展名,把將這個文件傳到你的機器上
10.在你的機器上使用下列命令將對方的公鑰導入
Linux$ gpg-import machine2.asc
并再次用gpg-list-keys命令看是否成功導入了對方的公鑰
11.接下來我們用做的就是對這把新導入的公鑰簽名
Linux$ gpg-sign-key machine2
注:這里machine2應是對方建立密鑰的real name
我們可以利用pgp-list-sigs來查看是否正確地對對方公鑰簽名了
采用同樣的方法將你的公鑰導出傳到對方的機器上
12.這樣我們就可以用對方的公鑰來加密文件了;首先建立一個文件
Linux$ eacho this is a test .>encryptfile
13.用對方的公鑰來加密此文件
Linux$ gpg-encypt-r receiver_public_keyname encryptfile
receiver_public_keyname在這里應為接收者的公鑰名字;執行完畢后,會生成
加密后的文件encryptfile.gpg,我們cat encryptfile.gpg輸出結果,看看怎樣!
14.將此加密后的文件傳到對方機器上,接收方用下命令解密
gpg –decrypt encryptfile.gpg
輸入正確的passphrase后,會生成解密后的encryptfile文件。
15.如果需要發送一封既加密又簽名的郵件內容,使用下面命令。
Gpg –se –r receiver_public_keyname filename
16.接收者收到這樣的信件,只需輸入:
gpg –d filename.gpg