美文网首页工作生活
SecureCRT解密AES-CBC模式.md

SecureCRT解密AES-CBC模式.md

作者: 未然猜 | 来源:发表于2019-07-02 18:11 被阅读0次

    找到配置文件位置

    SecureCRT配置文件位置.png

    找到密码密文

    密码密文.png

    解密代码

    # ! /usr/bin/env python
    # -*- coding: utf-8 -*-
    
    from Crypto.Hash import SHA256
    from Crypto.Cipher import AES
    
    def Decrypt(Ciphertext : str):
        """
        解密密文并返回相应的明文.
        Args: Ciphertext: 将被解密的十六进制字符串.
        Returns: 纯文本字符串.
        """
        IV = b'\x00' * AES.block_size
        Key = SHA256.new(''.encode('utf-8')).digest()
        cipher = AES.new(Key, AES.MODE_CBC, iv = IV)
        padded_plain_bytes = cipher.decrypt(bytes.fromhex(Ciphertext))
        
        plain_bytes_length = int.from_bytes(padded_plain_bytes[0:4], 'little')
        plain_bytes = padded_plain_bytes[4:4 + plain_bytes_length]
        if len(plain_bytes) != plain_bytes_length:
            raise ValueError('Invalid Ciphertext.')
    
        plain_bytes_digest = padded_plain_bytes[4 + plain_bytes_length:4 + plain_bytes_length + SHA256.digest_size]
        if len(plain_bytes_digest) != SHA256.digest_size:
            raise ValueError('Invalid Ciphertext.')
    
        if SHA256.new(plain_bytes).digest() != plain_bytes_digest:
            raise ValueError('Invalid Ciphertext.')
    
        return plain_bytes.decode('utf-8')
    
    # AES-CBC解密
    result = Decrypt('e6905d7f3c8ce60a2b06353ec4f5ec1f9d3e9f9c8965dd92e03995f5ec8ff67e37cbe8ef95b075b6e748ae23274d4bd8ddba0d9313f011b4d5d9e98a6468bcb2')
    print(result)
    

    相关文章

      网友评论

        本文标题:SecureCRT解密AES-CBC模式.md

        本文链接:https://www.haomeiwen.com/subject/lamthctx.html