如果您所在的环境包括GnuPG和Python> = 2.4,那么您还可以考虑使用python-
gnupg之类的工具。(免责声明:我是该项目的维护者。)这不费吹灰之力,
gpg并提供了一个相当简单的API。
API概述:
>>>导入gnupg>>> gpg = gnupg.GPG(gnupghome ='/ path / to / keyring / directory')>>> gpg.list_keys()[{ ... 'fingerprint':'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2', 'keyid':'197D5DAC68F1AAB2', 'length':'1024', 'type':'pub', 'uids':['','Gary Gross(测试用户)']}, { ... 'fingerprint':'37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A', 'keyid':'0C5FEFA7A921FC4A', 'length':'1024', ... 'uids':['','Danny Davis(测试用户)']}]>>>encryption= gpg.encrypt(“ Hello,world!”,['0C5FEFA7A921FC4A'])>>> str(Encrypted)'----- BEGIN PGPnews----- nedition:GnuPG v1.4.9(GNU / Linux) n nhQIOA / 6NHMDTXUwcEAf...----- END PGP讯息----- n'>>>decrypt= gpg.decrypt(str(encrypted),passphrase ='secret')>>> str(Decrypted)'Hello, world! '>>>Signature= gpg.sign (goodbye, world , password = secret)>>>Verified = verified= gpg.verify(str(signed))>>>If verified, print "verified", otherwise "not verified"“已验证”
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)