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


Python aead.AESCCM属性代码示例

本文整理汇总了Python中cryptography.hazmat.primitives.ciphers.aead.AESCCM属性的典型用法代码示例。如果您正苦于以下问题:Python aead.AESCCM属性的具体用法?Python aead.AESCCM怎么用?Python aead.AESCCM使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在cryptography.hazmat.primitives.ciphers.aead的用法示例。


在下文中一共展示了aead.AESCCM属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _encrypt

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import aead [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.aead import AESCCM [as 别名]
def _encrypt(backend, cipher, nonce, data, associated_data, tag_length):
    from cryptography.hazmat.primitives.ciphers.aead import AESCCM
    cipher_name = _aead_cipher_name(cipher)
    ctx = _aead_setup(
        backend, cipher_name, cipher._key, nonce, None, tag_length, _ENCRYPT
    )
    # CCM requires us to pass the length of the data before processing anything
    # However calling this with any other AEAD results in an error
    if isinstance(cipher, AESCCM):
        _set_length(backend, ctx, len(data))

    _process_aad(backend, ctx, associated_data)
    processed_data = _process_data(backend, ctx, data)
    outlen = backend._ffi.new("int *")
    res = backend._lib.EVP_CipherFinal_ex(ctx, backend._ffi.NULL, outlen)
    backend.openssl_assert(res != 0)
    backend.openssl_assert(outlen[0] == 0)
    tag_buf = backend._ffi.new("unsigned char[]", tag_length)
    res = backend._lib.EVP_CIPHER_CTX_ctrl(
        ctx, backend._lib.EVP_CTRL_AEAD_GET_TAG, tag_length, tag_buf
    )
    backend.openssl_assert(res != 0)
    tag = backend._ffi.buffer(tag_buf)[:]

    return processed_data + tag 
开发者ID:tp4a,项目名称:teleport,代码行数:27,代码来源:aead.py

示例2: Encrypt

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import aead [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.aead import AESCCM [as 别名]
def Encrypt(key_ccm, nonce, data, aad):
    aesccm = AESCCM(key_ccm, 8)
    return aesccm.encrypt(nonce, data, aad) 
开发者ID:robertmuth,项目名称:PyZwaver,代码行数:5,代码来源:security.py

示例3: _aead_cipher_name

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import aead [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.aead import AESCCM [as 别名]
def _aead_cipher_name(cipher):
    from cryptography.hazmat.primitives.ciphers.aead import (
        AESCCM, AESGCM, ChaCha20Poly1305
    )
    if isinstance(cipher, ChaCha20Poly1305):
        return b"chacha20-poly1305"
    elif isinstance(cipher, AESCCM):
        return "aes-{0}-ccm".format(len(cipher._key) * 8).encode("ascii")
    else:
        assert isinstance(cipher, AESGCM)
        return "aes-{0}-gcm".format(len(cipher._key) * 8).encode("ascii") 
开发者ID:tp4a,项目名称:teleport,代码行数:13,代码来源:aead.py

示例4: _decrypt

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import aead [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.aead import AESCCM [as 别名]
def _decrypt(backend, cipher, nonce, data, associated_data, tag_length):
    from cryptography.hazmat.primitives.ciphers.aead import AESCCM
    if len(data) < tag_length:
        raise InvalidTag
    tag = data[-tag_length:]
    data = data[:-tag_length]
    cipher_name = _aead_cipher_name(cipher)
    ctx = _aead_setup(
        backend, cipher_name, cipher._key, nonce, tag, tag_length, _DECRYPT
    )
    # CCM requires us to pass the length of the data before processing anything
    # However calling this with any other AEAD results in an error
    if isinstance(cipher, AESCCM):
        _set_length(backend, ctx, len(data))

    _process_aad(backend, ctx, associated_data)
    # CCM has a different error path if the tag doesn't match. Errors are
    # raised in Update and Final is irrelevant.
    if isinstance(cipher, AESCCM):
        outlen = backend._ffi.new("int *")
        buf = backend._ffi.new("unsigned char[]", len(data))
        res = backend._lib.EVP_CipherUpdate(ctx, buf, outlen, data, len(data))
        if res != 1:
            backend._consume_errors()
            raise InvalidTag

        processed_data = backend._ffi.buffer(buf, outlen[0])[:]
    else:
        processed_data = _process_data(backend, ctx, data)
        outlen = backend._ffi.new("int *")
        res = backend._lib.EVP_CipherFinal_ex(ctx, backend._ffi.NULL, outlen)
        if res == 0:
            backend._consume_errors()
            raise InvalidTag

    return processed_data 
开发者ID:tp4a,项目名称:teleport,代码行数:38,代码来源:aead.py

示例5: _aead_cipher_name

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import aead [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.aead import AESCCM [as 别名]
def _aead_cipher_name(cipher):
    from cryptography.hazmat.primitives.ciphers.aead import (
        AESCCM, AESGCM, ChaCha20Poly1305
    )
    if isinstance(cipher, ChaCha20Poly1305):
        return b"chacha20-poly1305"
    elif isinstance(cipher, AESCCM):
        return "aes-{}-ccm".format(len(cipher._key) * 8).encode("ascii")
    else:
        assert isinstance(cipher, AESGCM)
        return "aes-{}-gcm".format(len(cipher._key) * 8).encode("ascii") 
开发者ID:tp4a,项目名称:teleport,代码行数:13,代码来源:aead.py

示例6: _encrypt_ccm

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import aead [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.aead import AESCCM [as 别名]
def _encrypt_ccm(secret_key, value, field_max_length=None):
    aesccm = AESCCM(secret_key)
    nonce = os.urandom(AES_CCM_NONCE_LENGTH)
    ct = aesccm.encrypt(nonce, value.encode("utf-8"), None)
    encrypted = base64.b64encode(nonce + ct).decode("utf-8")
    if field_max_length:
        msg = "Tried to encode a value too large for this field"
        assert (len(encrypted) + _RESERVED_FIELD_SPACE) <= field_max_length, msg

    return encrypted 
开发者ID:quay,项目名称:quay,代码行数:12,代码来源:encryption.py

示例7: _decrypt_ccm

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import aead [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.aead import AESCCM [as 别名]
def _decrypt_ccm(secret_key, value):
    aesccm = AESCCM(secret_key)
    try:
        decoded = base64.b64decode(value)
        nonce = decoded[:AES_CCM_NONCE_LENGTH]
        ct = decoded[AES_CCM_NONCE_LENGTH:]
        decrypted = aesccm.decrypt(nonce, ct, None)
        return decrypted.decode("utf-8")
    except Exception:
        logger.exception("Got exception when trying to decrypt value `%s`", value)
        raise DecryptionFailureException()


# Defines the versions of encryptions we support. This will allow us to upgrade to newer encryption
# protocols (fairly seamlessly) if need be in the future. 
开发者ID:quay,项目名称:quay,代码行数:17,代码来源:encryption.py


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