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


Python KDF.PBKDF2屬性代碼示例

本文整理匯總了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)) 
開發者ID:RealityNet,項目名稱:kobackupdec,代碼行數:19,代碼來源:kobackupdec.py

示例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) 
開發者ID:RealityNet,項目名稱:kobackupdec,代碼行數:21,代碼來源:kobackupdec.py

示例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) 
開發者ID:RealityNet,項目名稱:kobackupdec,代碼行數:26,代碼來源:kobackupdec.py

示例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 
開發者ID:ClaudiuGeorgiu,項目名稱:Obfuscapk,代碼行數:13,代碼來源:const_string_encryption.py

示例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 
開發者ID:ClaudiuGeorgiu,項目名稱:Obfuscapk,代碼行數:13,代碼來源:res_string_encryption.py

示例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) 
開發者ID:BasioMeusPuga,項目名稱:Lector,代碼行數:6,代碼來源:rarfile.py

示例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') 
開發者ID:joxeankoret,項目名稱:CVE-2017-7494,代碼行數:8,代碼來源:crypto.py

示例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 
開發者ID:bomquote,項目名稱:transistor,代碼行數:13,代碼來源:browsercookie.py

示例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 
開發者ID:bomquote,項目名稱:transistor,代碼行數:12,代碼來源:browsercookie.py

示例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 
開發者ID:lykops,項目名稱:lykops,代碼行數:14,代碼來源:__init__.py

示例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) 
開發者ID:jaraco,項目名稱:keyrings.alt,代碼行數:11,代碼來源:file.py

示例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()) 
開發者ID:nneonneo,項目名稱:ffsend,代碼行數:8,代碼來源:ffsend.py

示例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()) 
開發者ID:r4sas,項目名稱:PBinCLI,代碼行數:17,代碼來源:format.py

示例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}} 
開發者ID:r4sas,項目名稱:PBinCLI,代碼行數:37,代碼來源:format.py

示例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) 
開發者ID:RNCryptor,項目名稱:RNCryptor-python,代碼行數:4,代碼來源:rncryptor.py


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