Как зашифровать и расшифровать данные с помощью ECC pycryptodome

#python-3.x #encryption #pycryptodome

#python-3.x #шифрование #pycryptodome

Вопрос:

Как мне зашифровать и расшифровать файлы или данные с помощью ECC с помощью pycryptodome? У меня есть генерация открытого ключа и закрытого ключа.

 def encrypt_message(key, message):
    """ Encrypts the message """
    # f = open(key, 'rb')
    # pubkey = ECC.import_key(f)
    # pubkey = str(pubkey)
    pubkey = key
    pubkey = pubkey.encode()
    print(pubkey)
    print(type(pubkey))
    cipher = AES.new(pubkey, AES.MODE_CBC) # Create a AES cipher object with the key using the mode CBC
    ciphered_data = cipher.encrypt(pad(message, AES.block_size)) # Pad the input data and then encrypt
    file = f'{message}.bin'
    file_out = open(file, "wb") # Open file to write bytes
    file_out.write(cipher.iv) # Write the iv to the output file (will be required for decryption)
    file_out.write(ciphered_data) # Write the varying length ciphertext to the file (this is the encrypted data)
    file_out.close()
 

Комментарии:

1. Посмотрите на это , чтобы увидеть разницу между RSA и ECC. ECC использует ECDH, который (как и ECIES) в настоящее время не поддерживается PyCryptodome .