本文整理匯總了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
示例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)
示例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)