本文整理汇总了Python中Crypto.Protocol.KDF.PBKDF2属性的典型用法代码示例。如果您正苦于以下问题:Python KDF.PBKDF2属性的具体用法?Python KDF.PBKDF2怎么用?Python KDF.PBKDF2使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类Crypto.Protocol.KDF
的用法示例。
在下文中一共展示了KDF.PBKDF2属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __decrypt_bkey_v4
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def __decrypt_bkey_v4(self):
key_salt = self._pwkey_salt[:16]
logging.debug('KEY_SALT[%s] = %s', len(key_salt),
binascii.hexlify(key_salt))
key = PBKDF2(self._upwd, key_salt, Decryptor.dklen, Decryptor.count,
Decryptor.prf)
logging.debug('KEY[%s] = %s', len(key), binascii.hexlify(key))
nonce = self._pwkey_salt[16:]
logging.debug('KEY NONCE[%s] = %s', len(nonce),
binascii.hexlify(nonce))
cipher = AES.new(key, mode=AES.MODE_GCM, nonce=nonce)
self._bkey = cipher.decrypt(self._e_perbackupkey)[:32]
logging.debug('BKEY[%s] = %s',
len(self._bkey), binascii.hexlify(self._bkey))
示例2: decrypt_package
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def decrypt_package(self, dec_material, data):
if not self._good:
logging.warning('well, it is hard to decrypt with a wrong key.')
if not dec_material.encMsgV3:
logging.error('cannot decrypt with an empty encMsgV3!')
return None
salt = dec_material.encMsgV3[:32]
counter_iv = dec_material.encMsgV3[32:]
key = PBKDF2(self._bkey, salt, Decryptor.dklen, Decryptor.count,
Decryptor.prf, hmac_hash_module=None)
counter_obj = Counter.new(128, initial_value=int.from_bytes(
counter_iv, byteorder='big'), little_endian=False)
decryptor = AES.new(key, mode=AES.MODE_CTR, counter=counter_obj)
return decryptor.decrypt(data)
示例3: decrypt_large_package
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def decrypt_large_package(self, dec_material, entry):
if not self._good:
logging.warning('well, it is hard to decrypt with a wrong key.')
if not dec_material.encMsgV3:
logging.error('cannot decrypt with an empty encMsgV3!')
return None
salt = dec_material.encMsgV3[:32]
counter_iv = dec_material.encMsgV3[32:]
key = PBKDF2(self._bkey, salt, Decryptor.dklen, Decryptor.count,
Decryptor.prf, hmac_hash_module=None)
counter_obj = Counter.new(128, initial_value=int.from_bytes(
counter_iv, byteorder='big'), little_endian=False)
decryptor = AES.new(key, mode=AES.MODE_CTR, counter=counter_obj)
data_len = entry.stat().st_size
with open(entry, 'rb') as entry_fd:
for x in range(0, data_len, self.chunk_size):
logging.debug('decrypting chunk %d of %s', x, entry)
data = entry_fd.read(self.chunk_size)
yield decryptor.decrypt(data)
示例4: encrypt_string
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def encrypt_string(self, string_to_encrypt: str) -> str:
# This is needed to remove the escaping added by Python. For example, if we find in smali the instruction
# const-string v0, "\"message\"" Android will treat it as "message" while in Python it's \"message\",
# so we need to encrypt "message" and not \"message\" (we have to remove the unnecessary escaping, otherwise
# the backslashes would by encrypted as part of the string).
string_to_encrypt = string_to_encrypt.encode(errors='replace').decode('unicode_escape')
key = PBKDF2(password=self.encryption_secret, salt=self.encryption_secret.encode(), dkLen=32, count=128)
encrypted_string = hexlify(AES.new(key=key, mode=AES.MODE_ECB)
.encrypt(pad(string_to_encrypt.encode(errors='replace'), AES.block_size))).decode()
return encrypted_string
示例5: encrypt_string
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def encrypt_string(self, string_to_encrypt: str) -> str:
# This is needed to remove the escaping added by Python. For example, if we find in string resources
# the string "\"message\"" Android will treat it as "message" while in Python it's \"message\", so we
# need to encrypt "message" and not \"message\" (we have to remove the unnecessary escaping, otherwise
# the backslashes would by encrypted as part of the string).
string_to_encrypt = string_to_encrypt.encode(errors='replace').decode('unicode_escape')
key = PBKDF2(password=self.encryption_secret, salt=self.encryption_secret.encode(), dkLen=32, count=128)
encrypted_string = hexlify(AES.new(key=key, mode=AES.MODE_ECB)
.encrypt(pad(string_to_encrypt.encode(errors='replace'), AES.block_size))).decode()
return encrypted_string
示例6: pbkdf2_sha256
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def pbkdf2_sha256(password, salt, iters):
"""PBKDF2 with HMAC-SHA256"""
ctx = pbkdf2.PBKDF2HMAC(hashes.SHA256(), 32, salt, iters, default_backend())
return ctx.derive(password)
示例7: string_to_key
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def string_to_key(cls, string, salt, params):
(iterations,) = unpack('>L', params or '\x00\x00\x10\x00')
prf = lambda p, s: HMAC.new(p, s, SHA).digest()
seed = PBKDF2(string, salt, cls.seedsize, iterations, prf)
tkey = cls.random_to_key(seed)
return cls.derive(tkey, 'kerberos')
示例8: _darwin_key
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def _darwin_key(self, salt, length):
"""
return key if sys.platform == 'darwin'
:return: PBKDF2 instance
"""
# running Chrome on OSX
my_pass = keyring.get_password('Chrome Safe Storage', 'Chrome')
my_pass = my_pass.encode('utf8')
iterations = 1003
key = PBKDF2(my_pass, salt, length, iterations)
return key
示例9: _linux_key
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def _linux_key(self, salt, length):
"""
return key if sys.platform == 'darwin'
:return: PBKDF2 instance
"""
# running Chrome on Linux
my_pass = 'peanuts'.encode('utf8')
iterations = 1
key = PBKDF2(my_pass, salt, length, iterations)
return key
示例10: _create_key
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def _create_key(b_password, b_salt, keylength, ivlength):
hash_function = SHA256
pbkdf2_prf = lambda p, s: HMAC.new(p, s, hash_function).digest()
b_derivedkey = PBKDF2(
b_password,
b_salt,
dkLen=(2 * keylength) + ivlength,
count=10000,
prf=pbkdf2_prf)
return b_derivedkey
示例11: _create_cipher
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def _create_cipher(self, password, salt, IV):
"""
Create the cipher object to encrypt or decrypt a payload.
"""
from Crypto.Protocol.KDF import PBKDF2
from Crypto.Cipher import AES
pw = PBKDF2(password, salt, dkLen=self.block_size)
return AES.new(pw[: self.block_size], AES.MODE_CFB, IV)
示例12: derive_auth_key
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def derive_auth_key(secret, password=None, url=None):
if password is None:
return hkdf(64, secret, info=b'authentication')
else:
return PBKDF2(password.encode('utf8'), url.encode('utf8'), 64, 100,
lambda x, y: hmac.new(x, y, sha256).digest())
示例13: __deriveKey
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def __deriveKey(self, salt):
from Crypto.Protocol.KDF import PBKDF2
from Crypto.Hash import HMAC, SHA256
# Key derivation, using PBKDF2 and SHA256 HMAC
return PBKDF2(
self._key + self._password.encode(),
salt,
dkLen = int(self._block_bits / 8),
count = self._iteration_count,
prf = lambda password, salt: HMAC.new(
password,
salt,
SHA256
).digest())
示例14: _encryptV2
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def _encryptV2(self):
from pbincli.utils import json_encode
iv = get_random_bytes(int(self._tag_bits / 8))
salt = get_random_bytes(self._salt_bytes)
key = self.__deriveKey(salt)
# prepare encryption authenticated data and message
adata = [
[
b64encode(iv).decode(),
b64encode(salt).decode(),
self._iteration_count,
self._block_bits,
self._tag_bits,
'aes',
'gcm',
self._compression
],
self._formatter,
int(self._discussion),
int(self._burnafterreading)
]
cipher_message = {'paste':self._text}
if self._attachment:
cipher_message['attachment'] = self._attachment
cipher_message['attachment_name'] = self._attachment_name
cipher = self.__initializeCipher(key, iv, adata, int(self._tag_bits /8 ))
ciphertext, tag = cipher.encrypt_and_digest(self.__compress(json_encode(cipher_message)))
if self._debug: print("PBKDF2 Key:\t{}\nCipherText:\t{}\nCipherTag:\t{}"
.format(b64encode(key), b64encode(ciphertext), b64encode(tag)))
self._data = {'v':2,'adata':adata,'ct':b64encode(ciphertext + tag).decode(),'meta':{'expire':self._expiration}}
示例15: _pbkdf2
# 需要导入模块: from Crypto.Protocol import KDF [as 别名]
# 或者: from Crypto.Protocol.KDF import PBKDF2 [as 别名]
def _pbkdf2(self, password, salt, iterations=10000, key_length=32):
return KDF.PBKDF2(password, salt, dkLen=key_length, count=iterations, prf=self._prf)