gpg使用

来源:互联网 发布:淘宝无线端推广 编辑:程序博客网 时间:2024/05/10 02:00


原理:
每个人都有一对密钥————公钥和私钥。
使有公钥来加密文件,但不能解密文件,必须要有相应的私钥才行。也就是说加密和解密不是一个对称的过程。
把公钥分发出去,加密文件时使用了你的公钥。解密文件时,才可以使用你的私钥来解密文件。

在Linux系统中,gpg程序可以实现非对称加密。
下面简单介绍gpg命令的用法:
一、创建密钥:
$ gpg --gen-key

Please select what kind of key you want:(选择密钥的种类)
   (1) DSA and ElGamal (default)
   (2) DSA (sign only)
   (4) RSA (sign only)

DSA keypair will 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)(选择密钥的长度)

Requested keysize is 1024 bits
Please specify how long the key should be valid.
         0 = key does not expire
        = key expires in n days
      w = key expires in n weeks
      m = key expires in n months
      y = key expires in n years
Key is valid for? (0)(选择密钥的有效期)

You need a User-ID to identify your key; the software constructs the user id
from Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) "

Real name:(密钥的表示名)
Email address: (Email地址)
Comment:(说明)

You need a Passphrase to protect your secret key.
Enter passphrase:(解密密码)

密钥建立完成

二、查看公钥
$ gpg --list-key

三、查看私钥
$ gpg --list-secret-key

四、公钥删除
$ gpg --delete-keys 标识名

五、私钥删除
$ gpg --delete-secret-keys 标识名

六、公钥导出
$ gpg --export 标识名 > 导出文件名(多以asc为文件后缀)

七、私钥导出
$ gpg --export-secret-key 标识名 > 导出文件名(多以asc为文件后缀)

八、密钥导入
$ gpg --import 密钥文件

九、加密文件
$ gpg --recipient 标识名 --encrypt 文件名

十、解密文件
$ gpg --output 新文件名 --decrypt 加密文件名

十一、修改密钥
$ gpg --edit-key 标识名

0 0
原创粉丝点击