pgp (GnuPG) encryption/decryption

GNU Privacy Guard(GnuPG或GPG)是一個密碼學軟體,用於加密、簽章通信內容及管理非對稱密碼學的金鑰

GNU Privacy Guard is a complete and free implementation of the OpenPGP Standard as defined RFC4880(also known as GPG).

//generate pub/private key

gpg --gen-key //select RSA-RSA

 

//export public key

gpg --armor --export peter@163.com > mykey.asc

 

//decrypt file which had been encrypted with public key

gpg --decrypt-file file.gpg

 

//import other guys's pub key

gpg --import lawrence.asc

 

//list keys

gpg --list-key

gpg $gpg --list-key
/home/peter/.gnupg/pubring.gpg
----------------------------------
pub   2048R/4EE235B6 2020-03-10
uid                  peter (peter from 163) <peter@163.com>
sub   2048R/826F97FB 2020-03-10

pub   2048R/D5D18161 2018-09-25
uid                  lawrence <lawrence@amlogic.com>
sub   2048R/7769D883 2018-09-25

 

//encrypt file with private key and output msg.txt.gpg

gpg --encrypt-file msg.txt -r peter -r lawrence

 

//Expired Subkey

​
gpg $gpg --list-key
/home/peter/.gnupg/pubring.gpg
----------------------------------
pub   2048R/4EE235B6 2020-03-10
uid                  peter (peter from 163) <peter@163.com>
sub   2048R/826F97FB 2020-03-10


gpg $gpg --edit-key 826F97FB
gpg (GnuPG) 1.4.20; Copyright (C) 2015 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.

Secret key is available.

pub  2048R/4EE235B6  created: 2020-03-10  expires: never       usage: SC  
                     trust: ultimate      validity: ultimate
sub  2048R/826F97FB  created: 2020-03-10  expires: never       usage: E   
[ultimate] (1). peter (peter from 163) <peter@163.com>

gpg> key 1

pub  2048R/4EE235B6  created: 2020-03-10  expires: never       usage: SC  
                     trust: ultimate      validity: ultimate
sub* 2048R/826F97FB  created: 2020-03-10  expires: never       usage: E   
[ultimate] (1). peter (peter from 163) <peter@163.com>

gpg> expire
Changing expiration time for a subkey.
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) 0
Key does not expire at all
Is this correct? (y/N) y

​

 

参考:

https://gnupg.org/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值