GPG加密和解密

Mac安装GPG命令

brew install gnupg
其他系统请参考
#GPG命令

创建密钥

gpg --gen-key
根据提示进行,此处没有难度,这里不再复述
需要注意的,到下面这一步,我们需要做一些操作,以便产生更安全的随机数

We need to generate a lot of random bytes. It is a good idea to perform some 
other action (type on the keyboard, move the mouse, utilize the disks) during the
prime generation; this gives the random number generator a better chance to 
gain enough entropy.```
此处我们填写的 “真实姓名” 是abc(后面会用到)

##查看密钥
查看私钥:`gpg -k`
查看公钥:`gpg --list-keys`

##导出密钥
导出公钥:`gpg -o abc.gpg -a --export abc`
导出私钥:`gpg -o abc-private.gpg --export-secret-keys abc`

##导入密钥
导入:`gpg --import filename`
公钥、私钥通用

##加密
加密文件:music.jpg,路径:/Users/Shared/doc
`gpg -o /Users/Shared/doc/music.jpg.gpg -er abc /Users/Shared/doc/music.jpg`

##解密
`gpg -o /Users/Shared/doc/music.jpg -d /Users/Shared/doc/music.jpg.gpg`
此时,需要输入创建密钥时的密码,就可以把文件解密出来
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容