本文整理汇总了Python中Crypto.Cipher.Blowfish.new方法的典型用法代码示例。如果您正苦于以下问题:Python Blowfish.new方法的具体用法?Python Blowfish.new怎么用?Python Blowfish.new使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crypto.Cipher.Blowfish
的用法示例。
在下文中一共展示了Blowfish.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cookie_encode
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [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: rc4_encrypt
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def rc4_encrypt(self, key: str, hex_key: bool = False):
"""Encrypt raw state with RC4
Args:
key (str): Required. Secret key
hex_key (bool, optional): If key is in hex. Defaults to False.
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("some data").rc4_encrypt("736563726574", hex_key=True).o
b"9e59bf79a2c0b7d253"
"""
if hex_key:
key = binascii.unhexlify(key)
if isinstance(key, str):
key = key.encode()
cipher = ARC4.new(key)
self.state = binascii.hexlify(cipher.encrypt(self._convert_to_bytes()))
return self
示例3: rc4_decrypt
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def rc4_decrypt(self, key: str, hex_key: bool = False):
"""Decrypt raw state with RC4
Args:
key (str): Required. Secret key
hex_key (bool, optional): If key is in hex. Defaults to False.
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("9e59bf79a2c0b7d253").hex_to_str().rc4_decrypt("secret").o
b"some data"
"""
if hex_key:
key = binascii.unhexlify(key)
if isinstance(key, str):
key = key.encode()
cipher = ARC4.new(key)
self.state = cipher.decrypt(self._convert_to_bytes())
return self
示例4: encrypt
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def encrypt(imagename,password):
img = Image.open( imagename )
img.load()
data = np.asarray( img, dtype="int32" )
H, W = len(data), len(data[0])
print(H)
print(W)
pixelstring= ""
for t in data:
for p in t:
for i in p:
pixelstring= pixelstring + str(100+i)
pixelstring= pixelstring+','+str(H)+','+str(W)
crypt_obj = Blowfish.new(password, Blowfish.MODE_ECB)
ciphertext = crypt_obj.encrypt(pad_string(pixelstring))
cipher= open(imagename+'.crypt', 'w')
cipher.write(ciphertext)
示例5: decrypt
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def decrypt(ciphername,password):
cipher= open(ciphername, 'r')
ciphertext= cipher.read()
crypt_obj = Blowfish.new(password, Blowfish.MODE_ECB)
pixelstring= crypt_obj.decrypt(ciphertext)
x= pixelstring.split(',')
H,W= int(x[-2]),int(x[-1])
pixelstring= x[0]
pixelstring= [int(pixelstring[i:i+3])-100 for i in range(0, len(pixelstring), 3)]
data = np.zeros((H, W, 3), dtype=np.uint8)
c= 0
for i in range(H):
for j in range(W):
data[i,j]= pixelstring[c], pixelstring[c+1], pixelstring[c+2]
c=c+3
img = Image.fromarray(data, 'RGB')
x= ciphername.split('.')
img.save(x[0]+'_dec.'+x[-2])
img.show()
示例6: run
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def run(self, module):
if not HAVE_PYCRYPTO:
module.log('warning', 'thoughtcrime: missing dependency: pycrypto')
return None
if self.zipfile and 'res/raw/blfs.key' in self.zipfile.namelist() and 'res/raw/config.cfg' in self.zipfile.namelist():
iv = "12345678" # this has to be done better
key = self.zipfile.open('res/raw/blfs.key').read()
key = ''.join(['%x' % ord(x) for x in key])[0:50]
cipher = Blowfish.new(key, Blowfish.MODE_CBC, iv)
decode = base64.b64decode(self.zipfile.open('res/raw/config.cfg').read())
config = cipher.decrypt(decode)
config = config[:config.find('</config>') + 9]
config = ET.fromstring(config)
c2 = config.findall('.//data')[0].get('url_main').split(';')
phone = config.findall('.//data')[0].get('phone_number')
module.add_ioc(c2, ['thoughtcrime', 'c2'])
return json.dumps({'c2': c2, 'phone': phone}, indent=2)
else:
return None
示例7: decrypt_xor
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def decrypt_xor(key, data):
cipher = XOR.new(key)
return cipher.decrypt(data)
# RC4
示例8: decrypt_arc4
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def decrypt_arc4(key, data):
cipher = ARC4.new(key)
return cipher.decrypt(data)
# DES
示例9: decrypt_des_ecb
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def decrypt_des_ecb(key, data, iv=None):
mode = DES.MODE_ECB
if iv:
cipher = DES.new(key, mode, iv)
else:
cipher = DES.new(key, mode)
return cipher.decrypt(data)
示例10: decrypt_des_cbc
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def decrypt_des_cbc(key, data, iv=None):
mode = DES.MODE_CBC
if iv:
cipher = DES.new(key, mode, iv)
else:
cipher = DES.new(key, mode)
return cipher.decrypt(data)
# DES3
示例11: decrypt_des3
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def decrypt_des3(key, data):
cipher = DES3.new(key)
return cipher.decrypt(data)
# AES
示例12: decrypt_aes_cbc_iv
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def decrypt_aes_cbc_iv(key, iv, data):
mode = AES.MODE_CBC
cipher = AES.new(key, mode, IV=iv)
return cipher.decrypt(data)
# Blowfish
示例13: decrypt_blowfish
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def decrypt_blowfish(key, data):
cipher = Blowfish.new(key)
return cipher.decrypt(data)
# RC6 - Custom
示例14: __init__
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def __init__(self, key, session):
self.cipher = Blowfish.new(key, Blowfish.MODE_ECB)
self.session = session
示例15: cookie_decode
# 需要导入模块: from Crypto.Cipher import Blowfish [as 别名]
# 或者: from Crypto.Cipher.Blowfish import new [as 别名]
def cookie_decode(self, cookie):
try:
a_iv, token = cookie.split(':')
iv = b64decode(a_iv)
cipher = Blowfish.new(self.KEY, Blowfish.MODE_CBC, iv)
cookie = cipher.decrypt(b64decode(token)).replace('@','')
except ValueError:
return (None, None)
return super(Authentication, self).cookie_decode(cookie)