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


Python Box.shared_key方法代码示例

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


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

示例1: test_equivalent_keys_shared_key_getter

# 需要导入模块: from nacl.public import Box [as 别名]
# 或者: from nacl.public.Box import shared_key [as 别名]
    def test_equivalent_keys_shared_key_getter(self):
        alices = PrivateKey.generate()
        alicesP = alices.public_key
        bobs, bobsprime = self._gen_equivalent_raw_keys_couple()
        bobsP, bobsprimeP = bobs.public_key, bobsprime.public_key

        assert bobsP == bobsprimeP

        box_AB = Box(alices, bobsP)

        box_BA = Box(bobs, alicesP)
        box_BprimeA = Box(bobsprime, alicesP)

        assert box_AB.shared_key() == box_BA.shared_key()
        assert box_BprimeA.shared_key() == box_BA.shared_key()
开发者ID:lmctv,项目名称:pynacl,代码行数:17,代码来源:test_public.py

示例2: test_shared_key_getter

# 需要导入模块: from nacl.public import Box [as 别名]
# 或者: from nacl.public.Box import shared_key [as 别名]
    def test_shared_key_getter(self):
        """
        RFC 7748 "Elliptic Curves for Security" gives a set of test
        parameters for the Diffie-Hellman key exchange on Curve25519:

        6.1.  [Diffie-Hellman on] Curve25519
            [ . . . ]
        Alice's private key, a:
          77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a
        Alice's public key, X25519(a, 9):
          8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a
        Bob's private key, b:
          5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb
        Bob's public key, X25519(b, 9):
          de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f

        Since libNaCl/libsodium shared key generation adds an HSalsa20
        key derivation pass on the raw shared Diffie-Hellman key, which
        is not exposed by itself, we just check the shared key for equality.
        """
        prv_A = (b'77076d0a7318a57d3c16c17251b26645'
                 b'df4c2f87ebc0992ab177fba51db92c2a')
        pub_A = (b'8520f0098930a754748b7ddcb43ef75a'
                 b'0dbf3a0d26381af4eba4a98eaa9b4e6a')
        prv_B = (b'5dab087e624a8a4b79e17f8b83800ee6'
                 b'6f3bb1292618b6fd1c2f8b27ff88e0eb')
        pub_B = (b'de9edb7d7b7dc1b4d35b61c2ece43537'
                 b'3f8343c85b78674dadfc7e146f882b4f')

        alices = PrivateKey(binascii.unhexlify(prv_A))
        bobs = PrivateKey(binascii.unhexlify(prv_B))
        alicesP = alices.public_key
        bobsP = bobs.public_key

        assert binascii.unhexlify(pub_A) == bytes(alicesP)
        assert binascii.unhexlify(pub_B) == bytes(bobsP)

        box_AB = Box(alices, bobsP)
        box_BA = Box(bobs, alicesP)

        assert box_AB.shared_key() == box_BA.shared_key()
开发者ID:maqp,项目名称:pynacl,代码行数:43,代码来源:test_public.py


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