看了很多博客,特别是关于python API 操作 GPG 的,真垃圾,掉坑里了。
最近项目在传输文件,需要进行加密、解密操作。
用我的代码就行
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31# coding=utf-8 """ Note! pip install pretty_bad_protocol """ import os class gpg_encrypt_decrypt(object): def __init__(self): self.path = os.getcwd() self.input_path = '/home/qazwsx/test_up/' self.output_path = '/home/qazwsx/test_down/' # self.homedir = '/home/hadoop/.gnupg' def encrypt_file(self, out_file_path): encryed_file = out_file_path.split('/')[-1][0:-3] + 'gng' encry_pt = 'gpg --recipient 用户 --always-trust --output %s --encrypt %s' % (encryed_file, out_file_path) print(encry_pt) os.system(encry_pt) return encryed_file def decrypt_file(self, input_file): decry_input_file = input_file[0:-3] + 'txt' decry_str = "echo '密码' | gpg --batch --passphrase-fd 0 --recipient 用户 --decrypt %s > %s" %( input_file, decry_input_file) os.system(decry_str) print(decry_str) return decry_input_file if __name__ == '__main__': ged = gpg_encrypt_decrypt() ged.encrypt_file('mat_20190705180023_20190706_0.txt') #ged = gpg_encrypt_decrypt() #ged.decrypt_file('')
对于gpg 的理解,常用命令,看阮一峰的博客就够了!!!!
千万别看别的博客,坑爹。!!!!!!!1
http://www.ruanyifeng.com/blog/2013/07/gpg.html
最后
以上就是魁梧鱼最近收集整理的关于GPG 对文件加密的全部内容,更多相关GPG内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复