當前位置: 首頁>>代碼示例>>Python>>正文


Python cmac.CMAC類代碼示例

本文整理匯總了Python中cryptography.hazmat.primitives.cmac.CMAC的典型用法代碼示例。如果您正苦於以下問題:Python CMAC類的具體用法?Python CMAC怎麽用?Python CMAC使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CMAC類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_invalid_verify

    def test_invalid_verify(self, backend):
        key = b"2b7e151628aed2a6abf7158809cf4f3c"
        cmac = CMAC(AES(key), backend)
        cmac.update(b"6bc1bee22e409f96e93d7e117393172a")

        with pytest.raises(InvalidSignature):
            cmac.verify(b"foobar")
開發者ID:OspreyX,項目名稱:cryptography,代碼行數:7,代碼來源:test_cmac.py

示例2: test_aes_verify

    def test_aes_verify(self, backend, params):
        key = params["key"]
        message = params["message"]
        output = params["output"]

        cmac = CMAC(AES(binascii.unhexlify(key)), backend)
        cmac.update(binascii.unhexlify(message))
        assert cmac.verify(binascii.unhexlify(output)) is None
開發者ID:OspreyX,項目名稱:cryptography,代碼行數:8,代碼來源:test_cmac.py

示例3: test_aes_generate

    def test_aes_generate(self, backend, params):
        key = params["key"]
        message = params["message"]
        output = params["output"]

        cmac = CMAC(AES(binascii.unhexlify(key)), backend)
        cmac.update(binascii.unhexlify(message))
        assert binascii.hexlify(cmac.finalize()) == output
開發者ID:OspreyX,項目名稱:cryptography,代碼行數:8,代碼來源:test_cmac.py

示例4: test_copy

def test_copy():
    backend = DummyCMACBackend([AES])
    copied_ctx = pretend.stub()
    pretend_ctx = pretend.stub(copy=lambda: copied_ctx)
    key = b"2b7e151628aed2a6abf7158809cf4f3c"
    cmac = CMAC(AES(key), backend=backend, ctx=pretend_ctx)

    assert cmac._backend is backend
    assert cmac.copy()._backend is backend
開發者ID:OspreyX,項目名稱:cryptography,代碼行數:9,代碼來源:test_cmac.py

示例5: test_verify_reject_unicode

    def test_verify_reject_unicode(self, backend):
        key = b"2b7e151628aed2a6abf7158809cf4f3c"
        cmac = CMAC(AES(key), backend)

        with pytest.raises(TypeError):
            cmac.update(six.u(''))

        with pytest.raises(TypeError):
            cmac.verify(six.u(''))
開發者ID:OspreyX,項目名稱:cryptography,代碼行數:9,代碼來源:test_cmac.py

示例6: test_3des_generate

    def test_3des_generate(self, backend, params):
        key1 = params["key1"]
        key2 = params["key2"]
        key3 = params["key3"]

        key = key1 + key2 + key3

        message = params["message"]
        output = params["output"]

        cmac = CMAC(TripleDES(binascii.unhexlify(key)), backend)
        cmac.update(binascii.unhexlify(message))
        assert binascii.hexlify(cmac.finalize()) == output
開發者ID:OspreyX,項目名稱:cryptography,代碼行數:13,代碼來源:test_cmac.py

示例7: test_3des_verify

    def test_3des_verify(self, backend, params):
        key1 = params["key1"]
        key2 = params["key2"]
        key3 = params["key3"]

        key = key1 + key2 + key3

        message = params["message"]
        output = params["output"]

        cmac = CMAC(TripleDES(binascii.unhexlify(key)), backend)
        cmac.update(binascii.unhexlify(message))
        assert cmac.verify(binascii.unhexlify(output)) is None
開發者ID:OspreyX,項目名稱:cryptography,代碼行數:13,代碼來源:test_cmac.py

示例8: test_copy

def test_copy():
    @utils.register_interface(CMACBackend)
    class PretendBackend(object):
        pass

    pretend_backend = PretendBackend()
    copied_ctx = pretend.stub()
    pretend_ctx = pretend.stub(copy=lambda: copied_ctx)
    key = b"2b7e151628aed2a6abf7158809cf4f3c"
    cmac = CMAC(AES(key), backend=pretend_backend, ctx=pretend_ctx)

    assert cmac._backend is pretend_backend
    assert cmac.copy()._backend is pretend_backend
開發者ID:B-Rich,項目名稱:cryptography,代碼行數:13,代碼來源:test_cmac.py

示例9: test_raises_after_finalize

    def test_raises_after_finalize(self, backend):
        key = b"2b7e151628aed2a6abf7158809cf4f3c"
        cmac = CMAC(AES(key), backend)
        cmac.finalize()

        with pytest.raises(AlreadyFinalized):
            cmac.update(b"foo")

        with pytest.raises(AlreadyFinalized):
            cmac.copy()

        with pytest.raises(AlreadyFinalized):
            cmac.finalize()
開發者ID:B-Rich,項目名稱:cryptography,代碼行數:13,代碼來源:test_cmac.py

示例10: test_aes_cmac

def test_aes_cmac(backend, wycheproof):
    key = binascii.unhexlify(wycheproof.testcase["key"])
    msg = binascii.unhexlify(wycheproof.testcase["msg"])
    tag = binascii.unhexlify(wycheproof.testcase["tag"])

    # skip truncated tags, which we don't support in the API
    if wycheproof.valid and len(tag) == 16:
        ctx = CMAC(AES(key), backend)
        ctx.update(msg)
        ctx.verify(tag)
    elif len(key) not in [16, 24, 32]:
        with pytest.raises(ValueError):
            CMAC(AES(key), backend)
    else:
        ctx = CMAC(AES(key), backend)
        ctx.update(msg)
        with pytest.raises(InvalidSignature):
            ctx.verify(tag)
開發者ID:amauryfa,項目名稱:cryptography,代碼行數:18,代碼來源:test_cmac.py

示例11: test_copy_with_backend

 def test_copy_with_backend(self, backend):
     key = b"2b7e151628aed2a6abf7158809cf4f3c"
     cmac = CMAC(AES(key), backend)
     cmac.update(b"6bc1bee22e409f96e93d7e117393172a")
     copy_cmac = cmac.copy()
     assert cmac.finalize() == copy_cmac.finalize()
開發者ID:OspreyX,項目名稱:cryptography,代碼行數:6,代碼來源:test_cmac.py


注:本文中的cryptography.hazmat.primitives.cmac.CMAC類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。