对称加密算法和非对称加密算法速度对比

测试环境:
CPU 1 核 Intel 2.2GHZ
内存 1GB

算法种类
对称加密算法AES CBC 模式
非对称加密算法RSA 256


加密明文长度为160 bytes
各运行10000次

上代码 test_aes.py

from Crypto.Cipher import AES
import time
obj = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
message = 'a' * 160
t1 = time.time()
for i in xrange(10000):
    ciphertext = obj.encrypt(message)
    obj2 = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
    text = obj2.decrypt(ciphertext)
    #print text
t2 = time.time()
print t2 - t1

test_rsa.py

from Crypto.PublicKey import RSA
import time
t1 = time.time()
key = RSA.generate(2048)
t2 = time.time()
print 'gen key', t2 - t1
#print key
#print key.exportKey()
#print RSA.exportKey('PEM')
message = 'a' * 160
t1 = time.time()
for i in xrange(10000):
    print i
    ciphertext = key.encrypt(message, None)
    key.decrypt(ciphertext)
t2 = time.time()
print t2 - t1
算法耗时
对称加密算法0.13
非对称加密算法193.16
非对称加密算法生成密钥对0.68


对称加密算法比非对称加密算法快大约1500倍
RSA 生成一个密钥都需要0.68秒, 可见对称加密算法比非对称加密算法有非常大得性能优势。

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值