首页 > 编程语言 > 详细

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

时间:2015-07-21 20:37:38      阅读:788      评论:0      收藏:0      [点我收藏+]

测试环境:
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秒, 可见对称加密算法比非对称加密算法有非常大得性能优势。

版权声明:本文为博主原创文章,未经博主允许不得转载。

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

原文:http://blog.csdn.net/woshiaotian/article/details/46990899

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!