python加密执行_如何在Python中执行PGP(生成密钥,加密/解密)

博客介绍了如何利用PyCrypto库在Python中实现PGP加密和解密操作。通过示例代码展示了如何创建加密和解密对象,并提供了PublicKey模块中与PGP相关的加密、解密、签名和验证方法。尽管文档不全,但可以参考Util/test.py模块测试脚本来了解其用法。
摘要由CSDN通过智能技术生成

PyCrypto支持PGP—尽管您应该测试它以确保它符合您的规范。

尽管文档很难获得,但是如果您查看Util/test.py(模块测试脚本),您可以找到它们的PGP支持的基本示例:if verbose: print ' PGP mode:',

obj1=ciph.new(password, ciph.MODE_PGP, IV)

obj2=ciph.new(password, ciph.MODE_PGP, IV)

start=time.time()

ciphertext=obj1.encrypt(str)

plaintext=obj2.decrypt(ciphertext)

end=time.time()

if (plaintext!=str):

die('Error in resulting plaintext from PGP mode')

print_timing(256, end-start, verbose)

del obj1, obj2

此外,PublicKey/pubkey.py提供了以下相关方法:def encrypt(self, plaintext, K)

def decrypt(self, ciphertext):

def sign(self, M, K):

def verify (self, M, signature):

def can_sign (self):

"""can_sign() : bool

Return a Boolean value recording whether this algorithm can

generate signatures. (This does not imply that this

particular key object has the private information required to

to generate a signature.)

"""

return 1

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值