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


Python MD5.new方法代码示例

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


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

示例1: decrypt_secret

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def decrypt_secret(secret, key):
    """Python implementation of SystemFunction005.

    Decrypts a block of data with DES using given key.
    Note that key can be longer than 7 bytes."""
    decrypted_data = ''
    j = 0   # key index
    for i in range(0,len(secret),8):
        enc_block = secret[i:i+8]
        block_key = key[j:j+7]
        des_key = str_to_key(block_key)

        des = DES.new(des_key, DES.MODE_ECB)
        decrypted_data += des.decrypt(enc_block)
        
        j += 7
        if len(key[j:j+7]) < 7:
            j = len(key[j:j+7])

    (dec_data_len,) = unpack("<L", decrypted_data[:4])
    return decrypted_data[8:8+dec_data_len] 
开发者ID:HarmJ0y,项目名称:ImpDump,代码行数:23,代码来源:lsasecrets.py

示例2: get_hbootkey

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def get_hbootkey(samaddr, bootkey):
    sam_account_path = ["SAM", "Domains", "Account"]

    root = get_root(samaddr)
    if not root: return None

    sam_account_key = open_key(root, sam_account_path)
    if not sam_account_key: return None

    F = None
    for v in values(sam_account_key):
        if v.Name == 'F':
            F = samaddr.read(v.Data.value, v.DataLength.value)
    if not F: return None

    md5 = MD5.new()
    md5.update(F[0x70:0x80] + aqwerty + bootkey + anum)
    rc4_key = md5.digest()

    rc4 = ARC4.new(rc4_key)
    hbootkey = rc4.encrypt(F[0x80:0xA0])
    
    return hbootkey 
开发者ID:HarmJ0y,项目名称:ImpDump,代码行数:25,代码来源:hashdump.py

示例3: get_hbootkey

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def get_hbootkey(sam_registry, bootkey):
    sam_account_path = ["SAM", "Domains", "Account"]

    sam_account_key = sam_registry.open_key(sam_account_path)

    # Get the F value
    F = sam_account_key.open_value("F").DecodedData
    if not F:
        return F

    md5 = MD5.new()
    md5.update(F[0x70:0x80] + aqwerty + bootkey + anum)
    rc4_key = md5.digest()

    rc4 = ARC4.new(rc4_key)
    hbootkey = rc4.encrypt(F[0x80:0xA0])

    return hbootkey 
开发者ID:google,项目名称:rekall,代码行数:20,代码来源:hashdump.py

示例4: decrypt

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def decrypt(cls, key, keyusage, ciphertext):
        if len(ciphertext) < 24:
            raise ValueError('ciphertext too short')
        cksum, basic_ctext = ciphertext[:16], ciphertext[16:]
        ki = HMAC.new(key.contents, cls.usage_str(keyusage), MD5).digest()
        ke = HMAC.new(ki, cksum, MD5).digest()
        basic_plaintext = ARC4.new(ke).decrypt(basic_ctext)
        exp_cksum = HMAC.new(ki, basic_plaintext, MD5).digest()
        ok = _mac_equal(cksum, exp_cksum)
        if not ok and keyusage == 9:
            # Try again with usage 8, due to RFC 4757 errata.
            ki = HMAC.new(key.contents, pack('<I', 8), MD5).digest()
            exp_cksum = HMAC.new(ki, basic_plaintext, MD5).digest()
            ok = _mac_equal(cksum, exp_cksum)
        if not ok:
            raise InvalidChecksum('ciphertext integrity failure')
        # Discard the confounder.
        return basic_plaintext[8:] 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:20,代码来源:crypto.py

示例5: GSS_GetMIC

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def GSS_GetMIC(self, sessionKey, data, sequenceNumber, direction = 'init'):
        GSS_GETMIC_HEADER = '\x60\x23\x06\x09\x2a\x86\x48\x86\xf7\x12\x01\x02\x02'
        token = self.MIC()

        # Let's pad the data
        pad = (4 - (len(data) % 4)) & 0x3
        padStr = chr(pad) * pad
        data += padStr
 
        token['SGN_ALG'] = GSS_HMAC
        if direction == 'init':
            token['SND_SEQ'] = struct.pack('>L', sequenceNumber) + '\x00'*4
        else:
            token['SND_SEQ'] = struct.pack('>L', sequenceNumber) + '\xff'*4

        Ksign = HMAC.new(sessionKey.contents, 'signaturekey\0', MD5).digest()
        Sgn_Cksum = MD5.new( struct.pack('<L',15) + str(token)[:8] + data).digest()
        Sgn_Cksum = HMAC.new(Ksign, Sgn_Cksum, MD5).digest()
        token['SGN_CKSUM'] = Sgn_Cksum[:8]

        Kseq = HMAC.new(sessionKey.contents, struct.pack('<L',0), MD5).digest()
        Kseq = HMAC.new(Kseq, token['SGN_CKSUM'], MD5).digest()
        token['SND_SEQ'] = ARC4.new(Kseq).encrypt(token['SND_SEQ'])
        finalData = GSS_GETMIC_HEADER + token.getData()
        return finalData 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:27,代码来源:gssapi.py

示例6: decrypt_aes

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def decrypt_aes(secret, key):
    """
    Based on code from http://lab.mediaservice.net/code/cachedump.rb
    """
    sha = SHA256.new()
    sha.update(key)
    for _i in range(1, 1000 + 1):
        sha.update(secret[28:60])
    aeskey = sha.digest()

    data = ""
    for i in range(60, len(secret), 16):
        aes = AES.new(aeskey, AES.MODE_CBC, '\x00' * 16)
        buf = secret[i : i + 16]
        if len(buf) < 16:
            buf += (16 - len(buf)) * "\00"
        data += aes.decrypt(buf)

    return data 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:21,代码来源:lsasecrets.py

示例7: decrypt_secret

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def decrypt_secret(secret, key):
    """Python implementation of SystemFunction005.

    Decrypts a block of data with DES using given key.
    Note that key can be longer than 7 bytes."""
    decrypted_data = ''
    j = 0   # key index
    for i in range(0, len(secret), 8):
        enc_block = secret[i:i + 8]
        block_key = key[j:j + 7]
        des_key = hashdump.str_to_key(block_key)

        des = DES.new(des_key, DES.MODE_ECB)
        enc_block = enc_block + "\x00" * int(abs(8 - len(enc_block)) % 8)
        decrypted_data += des.decrypt(enc_block)

        j += 7
        if len(key[j:j + 7]) < 7:
            j = len(key[j:j + 7])

    (dec_data_len,) = struct.unpack("<L", decrypted_data[:4])
    return decrypted_data[8:8 + dec_data_len] 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:24,代码来源:lsasecrets.py

示例8: decrypt_aes

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def decrypt_aes(secret, key):
    sha = SHA256.new()
    sha.update(key)
    for _i in range(1, 1000+1):
        sha.update(secret[28:60])
    aeskey = sha.digest()

    data = ""
    for i in range(60, len(secret), 16):
        aes = AES.new(aeskey, AES.MODE_CBC, "\x00"*16)
        buf = secret[i : i + 16]
        if len(buf) < 16:
            buf += (16-len(buf)) * "\00"

        data += aes.decrypt(buf)

    return data 
开发者ID:AlessandroZ,项目名称:LaZagneForensic,代码行数:19,代码来源:lsasecrets.py

示例9: sha1

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def sha1(self):
        """Get SHA1 hash
        
        The SHA (Secure Hash Algorithm) hash functions were designed by the NSA. 
        SHA-1 is the most established of the existing SHA hash functions and it is 
        used in a variety of security applications and protocols. However, SHA-1's 
        collision resistance has been weakening as new attacks are discovered or improved.

        Returns:
            Chepy: The Chepy object. 

        Examples:
            >>> Chepy("A").sha1().output
            "6dcd4ce23d88e2ee9568ba546c007c63d9131c1b"
        """
        self.state = hashlib.sha1(self._convert_to_bytes()).hexdigest()
        return self 
开发者ID:securisec,项目名称:chepy,代码行数:19,代码来源:hashing.py

示例10: sha2_512_truncate

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def sha2_512_truncate(self, truncate: int = 256):
        """Get SHA2-512/bits hash
        
        The SHA-2 (Secure Hash Algorithm 2) hash functions were designed by the NSA. SHA-2 
        includes significant changes from its predecessor, SHA-1. The SHA-2 family consists of 
        hash functions with digests (hash values) that are 224, 256, 384 or 512 bits: SHA224, 
        SHA256, SHA384, SHA512. SHA-512 operates on 64-bit words. SHA-256 operates on 32-bit 
        words. SHA-384 is largely identical to SHA-512 but is truncated to 384 bytes. SHA-224 
        is largely identical to SHA-256 but is truncated to 224 bytes. SHA-512/224 and SHA-512/256 
        are truncated versions of SHA-512, but the initial values are generated using the method 
        described in Federal Information Processing Standards (FIPS) PUB 180-4.

        Args:
            truncate (int, optional): The bits to truncate by. Defaults to 256

        Returns:
            Chepy: The Chepy object. 
        """
        assert truncate in [256, 224], "Valid truncates are 256, 224"
        h = SHA512.new(self._convert_to_bytes(), truncate=str(truncate))
        self.state = h.hexdigest()
        return self 
开发者ID:securisec,项目名称:chepy,代码行数:24,代码来源:hashing.py

示例11: md5

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def md5(self):
        """Get MD5 hash
        
        MD5 (Message-Digest 5) is a widely used hash function. It has been used 
        in a variety of security applications and is also commonly used to check 
        the integrity of files.<br><br>However, MD5 is not collision resistant and 
        it isn't suitable for applications like SSL/TLS certificates or digital 
        signatures that rely on this property.

        Returns:
            Chepy: The Chepy object. 

        Examples:
            >>> Chepy("A").md5().output
            "7fc56270e7a70fa81a5935b72eacbe29"
        """
        h = MD5.new()
        h.update(self._convert_to_bytes())
        self.state = h.hexdigest()
        return self 
开发者ID:securisec,项目名称:chepy,代码行数:22,代码来源:hashing.py

示例12: shake_256

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def shake_256(self, size: int = 64):
        """Get Shake-256 hash
        
        Shake is an Extendable Output Function (XOF) of the SHA-3 hash algorithm, 
        part of the Keccak family, allowing for variable output length/size.

        Args:
            size (int, optional): How many bytes to read, by default 64

        Returns:
            Chepy: The Chepy object. 
        """
        h = SHAKE256.new()
        h.update(self._convert_to_bytes())
        self.state = binascii.hexlify(h.read(size))
        return self 
开发者ID:securisec,项目名称:chepy,代码行数:18,代码来源:hashing.py

示例13: shake_128

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def shake_128(self, size: int = 64):
        """Get Shake-128 hash
        
        Shake is an Extendable Output Function (XOF) of the SHA-3 hash algorithm, 
        part of the Keccak family, allowing for variable output length/size.

        Args:
            size (int, optional): How many bytes to read, by default 64

        Returns:
            Chepy: The Chepy object. 
        """
        h = SHAKE128.new()
        h.update(self._convert_to_bytes())
        self.state = binascii.hexlify(h.read(size))
        return self 
开发者ID:securisec,项目名称:chepy,代码行数:18,代码来源:hashing.py

示例14: blake_2s

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def blake_2s(self, bits: int = 256, key: bytes = ""):
        """Get Blake-2s hash
        
        Performs BLAKE2s hashing on the input. BLAKE2s is a flavour of 
        the BLAKE cryptographic hash function that is optimized for 8- to 
        32-bit platforms and produces digests of any size between 1 and 32 bytes. 
        Supports the use of an optional key.
        
        Args:
            bits (int, optional): Number of digest bits, by default 256
            key (bytes, optional): Encryption secret key, by default ''
        
        Returns:
            Chepy: The Chepy object. 

        Examples:
            >>> Chepy("A").blake_2s(bits=128, key="key").output
            "4e33cc702e9d08c28a5e9691f23bc66a"
        """
        assert bits in [256, 160, 128], "Valid bits are 256, 160, 128"
        h = BLAKE2s.new(digest_bits=bits, key=key.encode())
        h.update(self._convert_to_bytes())
        self.state = h.hexdigest()
        return self 
开发者ID:securisec,项目名称:chepy,代码行数:26,代码来源:hashing.py

示例15: get_lsa_key

# 需要导入模块: from Crypto.Hash import MD5 [as 别名]
# 或者: from Crypto.Hash.MD5 import new [as 别名]
def get_lsa_key(secaddr, bootkey):
    root = get_root(secaddr)
    if not root:
        return None

    enc_reg_key = open_key(root, ["Policy", "PolSecretEncryptionKey"])
    if not enc_reg_key:
        return None

    enc_reg_value = enc_reg_key.ValueList.List[0]
    if not enc_reg_value:
        return None

    obf_lsa_key = secaddr.read(enc_reg_value.Data.value,
            enc_reg_value.DataLength.value)
    if not obf_lsa_key:
        return None

    md5 = MD5.new()
    md5.update(bootkey)
    for i in range(1000):
        md5.update(obf_lsa_key[60:76])
    rc4key = md5.digest()

    rc4 = ARC4.new(rc4key)
    lsa_key = rc4.decrypt(obf_lsa_key[12:60])

    return lsa_key[0x10:0x20] 
开发者ID:HarmJ0y,项目名称:ImpDump,代码行数:30,代码来源:lsasecrets.py


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