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


Python DES3.new方法代码示例

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


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

示例1: decrypt

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 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

示例2: messy_split

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 import new [as 别名]
def messy_split(long_line):
    # this is a messy way to split the data but it works for now.
    '''
    Split on = gives me the right sections but deletes the b64 padding
    use modulo math to restore padding.
    return new list.
    '''
    new_list = []
    old_list = long_line.split('=')
    for line in old_list:
        if len(line) != 0:
            line += "=" * ((4 - len(line) % 4) % 4)
            new_list.append(line)
    return new_list

# AES Decrypt 
开发者ID:opensourcesec,项目名称:CIRTKit,代码行数:18,代码来源:jrat.py

示例3: rc4_encrypt

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 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 
开发者ID:securisec,项目名称:chepy,代码行数:23,代码来源:encryptionencoding.py

示例4: rc4_decrypt

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 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 
开发者ID:securisec,项目名称:chepy,代码行数:23,代码来源:encryptionencoding.py

示例5: encryption_oracle_aes

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 import new [as 别名]
def encryption_oracle_aes(payload):
    global constant, prefix_len, suffix_len, secret
    if secret:
        if constant:
            payload = random_bytes(prefix_len) + payload + secret
        else:
            payload = random_bytes(random.randint(1, 50)) + payload + secret
    else:
        if constant:
            payload = random_bytes(prefix_len) + payload + random_bytes(suffix_len)
        else:
            payload = random_bytes(random.randint(1, 50)) + payload + random_bytes(random.randint(1, 50))

    payload = add_padding(payload, AES.block_size)
    cipher = AES.new(key_AES, AES.MODE_ECB)
    return cipher.encrypt(payload) 
开发者ID:GrosQuildu,项目名称:CryptoAttacks,代码行数:18,代码来源:test_ecb.py

示例6: encryption_oracle_des

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 import new [as 别名]
def encryption_oracle_des(payload):
    global constant, prefix_len, suffix_len, secret
    if secret:
        if constant:
            payload = random_bytes(prefix_len) + payload + secret
        else:
            payload = random_bytes(random.randint(1, 50)) + payload + secret
    else:
        if constant:
            payload = random_bytes(prefix_len) + payload + random_bytes(suffix_len)
        else:
            payload = random_bytes(random.randint(1, 50)) + payload + random_bytes(random.randint(1, 50))

    payload = add_padding(payload, DES3.block_size)
    cipher = DES3.new(key_DES3, DES3.MODE_ECB)
    return cipher.encrypt(payload) 
开发者ID:GrosQuildu,项目名称:CryptoAttacks,代码行数:18,代码来源:test_ecb.py

示例7: SignWith3Des

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 import new [as 别名]
def SignWith3Des(src):
    # 首先对字符串取MD5
    raw_buf = hashlib.md5(src.encode()).digest()
    # 对16字节的md5做bcd2ascii
    bcd_to_ascii = bytearray(32)
    for i in range(len(raw_buf)):
        bcd_to_ascii[2*i]   = raw_buf[i]>>4
        bcd_to_ascii[2*i+1] = raw_buf[i] & 0xf
    # hex_to_bin转换加密key
    key = bytes.fromhex('3ECA2F6FFA6D4952ABBACA5A7B067D23')
    # 对32字节的bcd_to_ascii做Triple DES加密(3DES/ECB/NoPadding)
    des3 = DES3.new(key, DES3.MODE_ECB)
    enc_bytes = des3.encrypt(bcd_to_ascii)
    # bin_to_hex得到最终加密结果
    enc_buf = ''.join(["%02X" % x for x in enc_bytes]).strip()
    return enc_buf

# 根据svrid查询client_msg_id 
开发者ID:wechat-tests,项目名称:PyMicroChat,代码行数:20,代码来源:Util.py

示例8: decrypt3DES

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 import new [as 别名]
def decrypt3DES(self, globalSalt, masterPassword, entrySalt, encryptedData):
        hp = sha1(globalSalt + masterPassword).digest()
        pes = entrySalt + '\x00' * (20 - len(entrySalt))
        chp = sha1(hp + entrySalt).digest()
        k1 = hmac.new(chp, pes + entrySalt, sha1).digest()
        tk = hmac.new(chp, pes, sha1).digest()
        k2 = hmac.new(chp, tk + entrySalt, sha1).digest()
        k = k1 + k2
        iv = k[-8:]
        key = k[:24]

        return DES3.new(key, DES3.MODE_CBC, iv).decrypt(encryptedData) 
开发者ID:mehulj94,项目名称:Radium,代码行数:14,代码来源:Mozilla.py

示例9: aes

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 import new [as 别名]
def aes(self):
        return AES.new(self.key, AES.MODE_ECB) # 初始化加密器 
开发者ID:inlike,项目名称:R-A-M-D-D3-S-M-H,代码行数:4,代码来源:RSA-AES-MD5-DES-DES3-MD5-SHA-HMAC.py

示例10: encrypt

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 import new [as 别名]
def encrypt(self, text):
        """
        传入明文
        :param text:bytes类型,长度是KEY的倍数
        :return:
        """
        if not isinstance(text, bytes):
            text = bytes(text, 'utf-8')
        x = len(text) % 8
        text = text+b'\0'*x
        cryptor = DES3.new(self.key, self.mode)
        ciphertext = cryptor.encrypt(text)
        return ciphertext 
开发者ID:inlike,项目名称:R-A-M-D-D3-S-M-H,代码行数:15,代码来源:RSA-AES-MD5-DES-DES3-MD5-SHA-HMAC.py

示例11: decrypt

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 import new [as 别名]
def decrypt(self, text):
        cryptor = DES3.new(self.key, self.mode)
        plain_text = cryptor.decrypt(text)
        st = str(plain_text.decode("utf-8")).rstrip('\0')
        return st 
开发者ID:inlike,项目名称:R-A-M-D-D3-S-M-H,代码行数:7,代码来源:RSA-AES-MD5-DES-DES3-MD5-SHA-HMAC.py

示例12: USE_HMAC

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 import new [as 别名]
def USE_HMAC(key, text):
    if not isinstance(key, bytes):
        key = bytes(key, 'utf-8')
    if not isinstance(text, bytes):
        text = bytes(text, 'utf-8')
    h = hmac.new(key, text, digestmod='MD5')
    return h.hexdigest() 
开发者ID:inlike,项目名称:R-A-M-D-D3-S-M-H,代码行数:9,代码来源:RSA-AES-MD5-DES-DES3-MD5-SHA-HMAC.py

示例13: decrypt_xor

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 import new [as 别名]
def decrypt_xor(key, data):
    cipher = XOR.new(key)
    return cipher.decrypt(data)


# RC4 
开发者ID:kevthehermit,项目名称:RATDecoders,代码行数:8,代码来源:crypto.py

示例14: decrypt_arc4

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 import new [as 别名]
def decrypt_arc4(key, data):
    cipher = ARC4.new(key)
    return cipher.decrypt(data)


# DES 
开发者ID:kevthehermit,项目名称:RATDecoders,代码行数:8,代码来源:crypto.py

示例15: decrypt_des_ecb

# 需要导入模块: from Crypto.Cipher import DES3 [as 别名]
# 或者: from Crypto.Cipher.DES3 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) 
开发者ID:kevthehermit,项目名称:RATDecoders,代码行数:9,代码来源:crypto.py


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