当前位置: 首页>>代码示例>>Python>>正文


Python HMAC.new方法代码示例

本文整理汇总了Python中Cryptodome.Hash.HMAC.new方法的典型用法代码示例。如果您正苦于以下问题:Python HMAC.new方法的具体用法?Python HMAC.new怎么用?Python HMAC.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cryptodome.Hash.HMAC的用法示例。


在下文中一共展示了HMAC.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: encrypt

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def encrypt(self, plaintext, esn):
        """
        Encrypt the given Plaintext with the encryption key
        :param plaintext:
        :return: Serialized JSON String of the encryption Envelope
        """
        init_vector = get_random_bytes(16)
        cipher = AES.new(self.encryption_key, AES.MODE_CBC, init_vector)
        ciphertext = base64.standard_b64encode(
            cipher.encrypt(Padding.pad(plaintext.encode('utf-8'), 16))).decode('utf-8')
        encryption_envelope = {
            'ciphertext': ciphertext,
            'keyid': '_'.join((esn, str(self.sequence_number))),
            'sha256': 'AA==',
            'iv': base64.standard_b64encode(init_vector).decode('utf-8')
        }
        return json.dumps(encryption_envelope) 
开发者ID:CastagnaIT,项目名称:plugin.video.netflix,代码行数:19,代码来源:default_crypto.py

示例2: encrypt_file

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def encrypt_file(file, keys=secretKeys()):
    '''Encrypt file data with the same method as the Send browser/js client'''
    key = keys.encryptKey
    iv = keys.encryptIV
    encData = tempfile.SpooledTemporaryFile(max_size=SPOOL_SIZE, mode='w+b')
    cipher = Cryptodome.Cipher.AES.new(key, Cryptodome.Cipher.AES.MODE_GCM, iv)

    pbar = progbar(fileSize(file))

    for chunk in iter(lambda: file.read(CHUNK_SIZE), b''):
        encData.write(cipher.encrypt(chunk))
        pbar.update(len(chunk))

    pbar.close()
    encData.write(cipher.digest())
    file.close()

    encData.seek(0)
    return encData 
开发者ID:ehuggett,项目名称:send-cli,代码行数:21,代码来源:upload.py

示例3: __decryptHash

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def __decryptHash(self, rid, cryptedHash, constant, newStyle = False):
        # Section 2.2.11.1.1 Encrypting an NT or LM Hash Value with a Specified Key
        # plus hashedBootKey stuff
        Key1,Key2 = self.__cryptoCommon.deriveKey(rid)

        Crypt1 = DES.new(Key1, DES.MODE_ECB)
        Crypt2 = DES.new(Key2, DES.MODE_ECB)

        if newStyle is False:
            rc4Key = self.MD5( self.__hashedBootKey[:0x10] + pack("<L",rid) + constant )
            rc4 = ARC4.new(rc4Key)
            key = rc4.encrypt(cryptedHash['Hash'])
        else:
            key = self.__cryptoCommon.decryptAES(self.__hashedBootKey[:0x10], cryptedHash['Hash'], cryptedHash['Salt'])[:16]

        decryptedHash = Crypt1.decrypt(key[:8]) + Crypt2.decrypt(key[8:])

        return decryptedHash 
开发者ID:Ridter,项目名称:Exchange2domain,代码行数:20,代码来源:dump.py

示例4: __decryptSecret

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def __decryptSecret(self, key, value):
        # [MS-LSAD] Section 5.1.2
        plainText = ''

        encryptedSecretSize = unpack('<I', value[:4])[0]
        value = value[len(value)-encryptedSecretSize:]

        key0 = key
        for i in range(0, len(value), 8):
            cipherText = value[:8]
            tmpStrKey = key0[:7]
            tmpKey = self.__cryptoCommon.transformKey(tmpStrKey)
            Crypt1 = DES.new(tmpKey, DES.MODE_ECB)
            plainText += Crypt1.decrypt(cipherText)
            key0 = key0[7:]
            value = value[8:]
            # AdvanceKey
            if len(key0) < 7:
                key0 = key[len(key0):]

        secret = LSA_SECRET_XP(plainText)
        return secret['Secret'] 
开发者ID:Ridter,项目名称:Exchange2domain,代码行数:24,代码来源:dump.py

示例5: __decryptLSA

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def __decryptLSA(self, value):
        if self.__vistaStyle is True:
            # ToDo: There could be more than one LSA Keys
            record = LSA_SECRET(value)
            tmpKey = self.__sha256(self.__bootKey, record['EncryptedData'][:32])
            plainText = self.__cryptoCommon.decryptAES(tmpKey, record['EncryptedData'][32:])
            record = LSA_SECRET_BLOB(plainText)
            self.__LSAKey = record['Secret'][52:][:32]

        else:
            md5 = hashlib.new('md5')
            md5.update(self.__bootKey)
            for i in range(1000):
                md5.update(value[60:76])
            tmpKey = md5.digest()
            rc4 = ARC4.new(tmpKey)
            plainText = rc4.decrypt(value[12:60])
            self.__LSAKey = plainText[0x10:0x20] 
开发者ID:Ridter,项目名称:Exchange2domain,代码行数:20,代码来源:dump.py

示例6: __decryptSecret

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def __decryptSecret(self, key, value):
        # [MS-LSAD] Section 5.1.2
        plainText = ''

        encryptedSecretSize = unpack('<I', value[:4])[0]
        value = value[len(value)-encryptedSecretSize:]

        key0 = key
        for i in range(0, len(value), 8):
            cipherText = value[:8]
            tmpStrKey = key0[:7]
            tmpKey = transformKey(tmpStrKey)
            Crypt1 = DES.new(tmpKey, DES.MODE_ECB)
            plainText += Crypt1.decrypt(cipherText)
            key0 = key0[7:]
            value = value[8:]
            # AdvanceKey
            if len(key0) < 7:
                key0 = key[len(key0):]

        secret = LSA_SECRET_XP(plainText)
        return secret['Secret'] 
开发者ID:Coalfire-Research,项目名称:Slackor,代码行数:24,代码来源:secretsdump.py

示例7: calculateChecksum

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def calculateChecksum(data):
 """The function used to calculate CIC checksums for xpd files"""
 return HMAC.new(constants.cicKey, data, SHA256).hexdigest() 
开发者ID:ma1co,项目名称:Sony-PMCA-RE,代码行数:5,代码来源:__init__.py

示例8: load_crypto_session

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def load_crypto_session(self, msl_data=None):
        try:
            self.encryption_key = base64.standard_b64decode(
                msl_data['encryption_key'])
            self.sign_key = base64.standard_b64decode(
                msl_data['sign_key'])
            if not self.encryption_key or not self.sign_key:
                raise MSLError('Missing encryption_key or sign_key')
            self.rsa_key = RSA.importKey(
                base64.standard_b64decode(msl_data['rsa_key']))
        except Exception:  # pylint: disable=broad-except
            common.debug('Generating new RSA keys')
            self.rsa_key = RSA.generate(2048)
            self.encryption_key = None
            self.sign_key = None 
开发者ID:CastagnaIT,项目名称:plugin.video.netflix,代码行数:17,代码来源:default_crypto.py

示例9: decrypt

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def decrypt(self, init_vector, ciphertext):
        """Decrypt a ciphertext"""
        cipher = AES.new(self.encryption_key, AES.MODE_CBC, init_vector)
        return Padding.unpad(cipher.decrypt(ciphertext), 16) 
开发者ID:CastagnaIT,项目名称:plugin.video.netflix,代码行数:6,代码来源:default_crypto.py

示例10: sign

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def sign(self, message):
        """Sign a message"""
        return base64.standard_b64encode(
            HMAC.new(self.sign_key, message.encode('utf-8'), SHA256).digest()).decode('utf-8') 
开发者ID:CastagnaIT,项目名称:plugin.video.netflix,代码行数:6,代码来源:default_crypto.py

示例11: _init_keys

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def _init_keys(self, key_response_data):
        cipher = PKCS1_OAEP.new(self.rsa_key)
        encrypted_encryption_key = base64.standard_b64decode(
            key_response_data['keydata']['encryptionkey'])
        encrypted_sign_key = base64.standard_b64decode(
            key_response_data['keydata']['hmackey'])
        self.encryption_key = _decrypt_key(encrypted_encryption_key, cipher)
        self.sign_key = _decrypt_key(encrypted_sign_key, cipher) 
开发者ID:CastagnaIT,项目名称:plugin.video.netflix,代码行数:10,代码来源:default_crypto.py

示例12: generate_session_key

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def generate_session_key(hmac_secret=b''):
    """
    :param hmac_secret: optional HMAC
    :type hmac_secret: :class:`bytes`
    :return: (session_key, encrypted_session_key) tuple
    :rtype: :class:`tuple`
    """
    session_key = random_bytes(32)
    encrypted_session_key = PKCS1_OAEP.new(UniverseKey.Public, SHA1)\
                                      .encrypt(session_key + hmac_secret)

    return (session_key, encrypted_session_key) 
开发者ID:ValvePython,项目名称:steam,代码行数:14,代码来源:crypto.py

示例13: symmetric_encrypt_ecb

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def symmetric_encrypt_ecb(message, key):
    return AES.new(key, AES.MODE_ECB).encrypt(pad(message)) 
开发者ID:ValvePython,项目名称:steam,代码行数:4,代码来源:crypto.py

示例14: symmetric_encrypt_iv

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def symmetric_encrypt_iv(iv, key):
    return AES.new(key, AES.MODE_ECB).encrypt(iv) 
开发者ID:ValvePython,项目名称:steam,代码行数:4,代码来源:crypto.py

示例15: symmetric_encrypt_with_iv

# 需要导入模块: from Cryptodome.Hash import HMAC [as 别名]
# 或者: from Cryptodome.Hash.HMAC import new [as 别名]
def symmetric_encrypt_with_iv(message, key, iv):
    encrypted_iv = symmetric_encrypt_iv(iv, key)
    cyphertext = AES.new(key, AES.MODE_CBC, iv).encrypt(pad(message))
    return encrypted_iv + cyphertext 
开发者ID:ValvePython,项目名称:steam,代码行数:6,代码来源:crypto.py


注:本文中的Cryptodome.Hash.HMAC.new方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。