35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
"""
|
|
This is a simple RSA encryptor/decryptor.
|
|
It uses a key pair which is stored in a 'keys' directory.
|
|
The keys are generated when you run the script.
|
|
The script will encrypt a message for you if you provide it.
|
|
The script will decrypt a message for you if you provide it.
|
|
The script will generate a key pair and save it in the 'keys' directory.
|
|
"""
|
|
|
|
import os
|
|
from RSA_Crypto.encrypt import RSAEncryptor
|
|
from RSA_Crypto.decrypt import RSADecryptor
|
|
from RSA_Crypto.generate_save import RSAKeyPair
|
|
|
|
KEYS_DIR = 'keys'
|
|
PRIVATE_KEY_FILE = f'{KEYS_DIR}/private-key.pem'
|
|
PUBLIC_KEY_FILE = f'{KEYS_DIR}/public-key.pem'
|
|
|
|
if not os.path.exists(KEYS_DIR):
|
|
os.makedirs(KEYS_DIR)
|
|
|
|
key_pair = RSAKeyPair(PRIVATE_KEY_FILE, PUBLIC_KEY_FILE,)
|
|
key_pair.generate_and_save_keys()
|
|
|
|
# Шифрование сообщения
|
|
message = "Это лицензионный ключ."
|
|
rsa_encryptor = RSAEncryptor(PUBLIC_KEY_FILE)
|
|
encrypted_message = rsa_encryptor.encrypt_message(message)
|
|
print("Зашифрованное сообщение (Base64):", encrypted_message)
|
|
|
|
# Дешифрование сообщения
|
|
rsa_decryptor = RSADecryptor(PRIVATE_KEY_FILE)
|
|
decrypted_message = rsa_decryptor.decrypt_message(encrypted_message)
|
|
print("Расшифрованное сообщение:", decrypted_message)
|