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


Python Blowfish.block_size方法代碼示例

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


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

示例1: cookie_encode

# 需要導入模塊: from Crypto.Cipher import Blowfish [as 別名]
# 或者: from Crypto.Cipher.Blowfish import block_size [as 別名]
def cookie_encode(self, *ids):
        cookie = super(Authentication, self).cookie_encode(*ids)

        bs = Blowfish.block_size
        iv = Random.new().read(bs)
        cipher = Blowfish.new(self.KEY, Blowfish.MODE_CBC, iv)
        # pad cookie to block size.
        # Cookie is ascii base64 + ':', so we can safely pad with '@'.
        missing_bytes = bs - (len(cookie) % bs)
        cookie += '@' * missing_bytes

        return '%s:%s' % (
            b64encode(iv),
            b64encode(cipher.encrypt(cookie))
        )

        return cookie 
開發者ID:Net-ng,項目名稱:kansha,代碼行數:19,代碼來源:security.py

示例2: encrypt_key

# 需要導入模塊: from Crypto.Cipher import Blowfish [as 別名]
# 或者: from Crypto.Cipher.Blowfish import block_size [as 別名]
def encrypt_key(text, salt_key):
    try:
        bs = Blowfish.block_size
        extra_bytes = len(text) % bs
        padding_size = bs - extra_bytes
        padding = chr(padding_size) * padding_size
        padded_text = text + padding

        crypt_obj = Blowfish.new(salt_key, Blowfish.MODE_ECB)

        cipher = crypt_obj.encrypt(padded_text)

        return cipher
    except Exception as ERROR:
        log.error(ERROR) 
開發者ID:globocom,項目名稱:GloboNetworkAPI,代碼行數:17,代碼來源:encrypt.py

示例3: generate_key

# 需要導入模塊: from Crypto.Cipher import Blowfish [as 別名]
# 或者: from Crypto.Cipher.Blowfish import block_size [as 別名]
def generate_key():
    try:
        bs = Blowfish.block_size
        return get_random_bytes(bs)

    except Exception as ERROR:
        log.error(ERROR) 
開發者ID:globocom,項目名稱:GloboNetworkAPI,代碼行數:9,代碼來源:encrypt.py


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