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


Python Hash.HMAC屬性代碼示例

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


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

示例1: expand

# 需要導入模塊: from Crypto import Hash [as 別名]
# 或者: from Crypto.Hash import HMAC [as 別名]
def expand( self ):
        """
        Return the expanded output key material.

        The output key material is calculated based on the given PRK, info and
        L.
        """

        tmp = ""

        # Prevent the accidental re-use of output keying material.
        if len(self.T) > 0:
            raise base.PluggableTransportError("HKDF-SHA256 OKM must not "
                                               "be re-used by application.")

        while self.length > len(self.T):
            tmp = Crypto.Hash.HMAC.new(self.prk, tmp + self.info +
                                       chr(self.ctr),
                                       Crypto.Hash.SHA256).digest()
            self.T += tmp
            self.ctr += 1

        return self.T[:self.length] 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:25,代碼來源:mycrypto.py

示例2: HMAC_SHA256_128

# 需要導入模塊: from Crypto import Hash [as 別名]
# 或者: from Crypto.Hash import HMAC [as 別名]
def HMAC_SHA256_128( key, msg ):
    """
    Return the HMAC-SHA256-128 of the given `msg' authenticated by `key'.
    """

    assert(len(key) >= const.SHARED_SECRET_LENGTH)

    h = Crypto.Hash.HMAC.new(key, msg, Crypto.Hash.SHA256)

    # Return HMAC truncated to 128 out of 256 bits.
    return h.digest()[:16] 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:13,代碼來源:mycrypto.py

示例3: extract

# 需要導入模塊: from Crypto import Hash [as 別名]
# 或者: from Crypto.Hash import HMAC [as 別名]
def extract( self, salt, ikm ):
        return Crypto.Hash.HMAC.new(salt, ikm, Crypto.Hash.SHA256).digest() 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:4,代碼來源:test_scramblesuit.py

示例4: test3_invalidHMAC

# 需要導入模塊: from Crypto import Hash [as 別名]
# 或者: from Crypto.Hash import HMAC [as 別名]
def test3_invalidHMAC( self ):
        # Make the HMAC invalid.
        handshake = self.udh.createHandshake()
        if handshake[-1] != 'a':
            handshake = handshake[:-1] + 'a'
        else:
            handshake = handshake[:-1] + 'b'

        buf = obfs_buf.Buffer(handshake)

        self.failIf(self.udh.receivePublicKey(buf, lambda x: x) == True) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:13,代碼來源:test_scramblesuit.py


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