当前位置: 首页>>代码示例>>Python>>正文


Python AES.encrypt方法代码示例

本文整理汇总了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]
开发者ID:HITGmbH,项目名称:py-convergent-encryption,代码行数:24,代码来源:crypto.py


注:本文中的pycryptopp.cipher.aes.AES.encrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。