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


Python MultiFernet.rotate方法代碼示例

本文整理匯總了Python中cryptography.fernet.MultiFernet.rotate方法的典型用法代碼示例。如果您正苦於以下問題:Python MultiFernet.rotate方法的具體用法?Python MultiFernet.rotate怎麽用?Python MultiFernet.rotate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cryptography.fernet.MultiFernet的用法示例。


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

示例1: test_rotate_decrypt_no_shared_keys

# 需要導入模塊: from cryptography.fernet import MultiFernet [as 別名]
# 或者: from cryptography.fernet.MultiFernet import rotate [as 別名]
    def test_rotate_decrypt_no_shared_keys(self, backend):
        f1 = Fernet(base64.urlsafe_b64encode(b"\x00" * 32), backend=backend)
        f2 = Fernet(base64.urlsafe_b64encode(b"\x01" * 32), backend=backend)

        mf1 = MultiFernet([f1])
        mf2 = MultiFernet([f2])

        with pytest.raises(InvalidToken):
            mf2.rotate(mf1.encrypt(b"abc"))
開發者ID:amauryfa,項目名稱:cryptography,代碼行數:11,代碼來源:test_fernet.py

示例2: test_rotate

# 需要導入模塊: from cryptography.fernet import MultiFernet [as 別名]
# 或者: from cryptography.fernet.MultiFernet import rotate [as 別名]
    def test_rotate(self, backend):
        f1 = Fernet(base64.urlsafe_b64encode(b"\x00" * 32), backend=backend)
        f2 = Fernet(base64.urlsafe_b64encode(b"\x01" * 32), backend=backend)

        mf1 = MultiFernet([f1])
        mf2 = MultiFernet([f2, f1])

        plaintext = b"abc"
        mf1_ciphertext = mf1.encrypt(plaintext)

        assert mf2.decrypt(mf1_ciphertext) == plaintext

        rotated = mf2.rotate(mf1_ciphertext)

        assert rotated != mf1_ciphertext
        assert mf2.decrypt(rotated) == plaintext

        with pytest.raises(InvalidToken):
            mf1.decrypt(rotated)
開發者ID:amauryfa,項目名稱:cryptography,代碼行數:21,代碼來源:test_fernet.py

示例3: test_rotate_preserves_timestamp

# 需要導入模塊: from cryptography.fernet import MultiFernet [as 別名]
# 或者: from cryptography.fernet.MultiFernet import rotate [as 別名]
    def test_rotate_preserves_timestamp(self, backend, monkeypatch):
        f1 = Fernet(base64.urlsafe_b64encode(b"\x00" * 32), backend=backend)
        f2 = Fernet(base64.urlsafe_b64encode(b"\x01" * 32), backend=backend)

        mf1 = MultiFernet([f1])
        mf2 = MultiFernet([f2, f1])

        plaintext = b"abc"
        mf1_ciphertext = mf1.encrypt(plaintext)

        later = datetime.datetime.now() + datetime.timedelta(minutes=5)
        later_time = time.mktime(later.timetuple())
        monkeypatch.setattr(time, "time", lambda: later_time)

        original_time, _ = Fernet._get_unverified_token_data(mf1_ciphertext)
        rotated_time, _ = Fernet._get_unverified_token_data(
            mf2.rotate(mf1_ciphertext)
        )

        assert later_time != rotated_time
        assert original_time == rotated_time
開發者ID:amauryfa,項目名稱:cryptography,代碼行數:23,代碼來源:test_fernet.py


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