本文整理汇总了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)