使用aespython进行ECB加解密示例

CBC示例:

from aespython import cbc_mode, key_expander, aes_cipher

key = 'MluJMEZegVmrnWDaBiG1j7lqpkxNHh1v'
key = map(ord, key)

iv  = 'cQUD1NUWNj0inTFp'
iv = map(ord, iv)

data = '9KWIuca1KKkB1Rna'

cipher = aes_cipher.AESCipher(key_expander.KeyExpander(256).expand(key))
cry = cbc_mode.CBCMode(cipher, 16)
cry.set_iv(iv)

encrypt_data = cry.encrypt_block(map(ord, data))

找了一下并没有叫ECB模式的示例,自己摸索并测试成功,记录代码片段如下(之前部分与CBC模式一致):

#AES 128bit
cipher = aes_cipher.AESCipher(key_expander.KeyExpander(128).expand(key))

encrypt_data = cipher.cipher_block(map(ord, data))

 

posted on 2016-08-20 11:58  aozima  阅读(2804)  评论(0编辑  收藏  举报

导航