本文整理汇总了Python中pycryptopp.cipher.aes.AES.encrypt方法的典型用法代码示例。如果您正苦于以下问题:Python AES.encrypt方法的具体用法?Python AES.encrypt怎么用?Python AES.encrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycryptopp.cipher.aes.AES
的用法示例。
在下文中一共展示了AES.encrypt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: aes
# 需要导入模块: from pycryptopp.cipher.aes import AES [as 别名]
# 或者: from pycryptopp.cipher.aes.AES import encrypt [as 别名]
def aes(key, data, counter=False):
""" encrypt data with aes, using either pycryptopp or PyCrypto.
Args
key: The encryption key
data: plain text data
counter: a callable, usually not needed
"""
# using either pycryptopp...
if hasattr(AES, "process"):
a = AES(key)
return a.process(data)
# ... or PyCrypto
counter = counter or Counter()
a = AES.new(key, AES.MODE_CTR, counter=counter)
rest = len(data) % 16
if not rest:
return a.encrypt(data)
# Data length must be a multiple of 16
# Pad with bytes all of the same value as the number of padding bytes
pad = (16 - rest)
data += chr(pad) * pad
return a.encrypt(data)[:-pad]