自学内容网 自学内容网

navicat密码解密python

其他资料都是用php写的,但是运行起来好像有点问题,提供python代码,首先注册表获取加密后的密码,然后运行下述代码解密。
参考:获取navicat密码

import hashlib
from Crypto.Cipher import AES, Blowfish
from Crypto.Util.Padding import pad, unpad
from binascii import unhexlify, hexlify

class NavicatPassword:
    def __init__(self, version=12):
        self.version = version
        self.aes_key = b'libcckeylibcckey'
        self.aes_iv = b'libcciv libcciv '
        self.blow_string = '3DC5CA39'
        self.blow_key = hashlib.sha1(b'3DC5CA39').digest()
        self.blow_iv = bytes.fromhex('d9c7c3c8870d64bd')

    def xor_bytes(self, str1, str2):
        return bytes([a ^ b for a, b in zip(str1, str2)])

    def encrypt(self, string):
        if self.version == 11:
            return self.encrypt_eleven(string)
        elif self.version == 12:
            return self.encrypt_twelve(string)
        else:
            return None

    def encrypt_eleven(self, string):
        string = pad(string.encode(), Blowfish.block_size)
        rounds = len(string) // 8
        left_length = len(string) % 8
        result = b''
        current_vector = self.blow_iv
        for i in range(rounds):
            block = string[i * 8:(i + 1) * 8]
            temp = self.encrypt_block(self.xor_bytes(block, current_vector))
            current_vector = self.xor_bytes(current_vector, temp)
            result += temp
        if left_length:
            current_vector = self.encrypt_block(current_vector)
            result += self.xor_bytes(string[rounds * 8:], current_vector)
        return hexlify(result).upper().decode()

    def encrypt_block(self, block):
        cipher = Blowfish.new(self.blow_key, Blowfish.MODE_ECB)
        return cipher.encrypt(block)

    def decrypt_block(self, block):
        cipher = Blowfish.new(self.blow_key, Blowfish.MODE_ECB)
        return cipher.decrypt(block)

    def encrypt_twelve(self, string):
        cipher = AES.new(self.aes_key, AES.MODE_CBC, self.aes_iv)
        result = cipher.encrypt(pad(string.encode(), AES.block_size))
        return hexlify(result).upper().decode()

    def decrypt(self, string):
        if self.version == 11:
            return self.decrypt_eleven(string)
        elif self.version == 12:
            return self.decrypt_twelve(string)
        else:
            return None

    def decrypt_eleven(self, upper_string):
        string = unhexlify(upper_string.lower())
        rounds = len(string) // 8
        left_length = len(string) % 8
        result = b''
        current_vector = self.blow_iv
        for i in range(rounds):
            encrypted_block = string[i * 8:(i + 1) * 8]
            temp = self.xor_bytes(self.decrypt_block(encrypted_block), current_vector)
            current_vector = self.xor_bytes(current_vector, encrypted_block)
            result += temp
        if left_length:
            current_vector = self.encrypt_block(current_vector)
            result += self.xor_bytes(string[rounds * 8:], current_vector)
        return result.decode(errors='ignore')

    def decrypt_twelve(self, upper_string):
        string = unhexlify(upper_string.lower())
        cipher = AES.new(self.aes_key, AES.MODE_CBC, self.aes_iv)
        return unpad(cipher.decrypt(string), AES.block_size).decode()

# Example usage
navicat_password = NavicatPassword(11)
decoded = navicat_password.decrypt('7EAA549760822DA9A89CBBE9')
print(decoded)



原文地址:https://blog.csdn.net/sinat_34233802/article/details/143965837

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!