diff --git a/1ano/2semestre/labi/tema01/src/publicKey_RSA.py b/1ano/2semestre/labi/tema01/src/publicKey_RSA.py new file mode 100644 index 0000000..f5fbed7 --- /dev/null +++ b/1ano/2semestre/labi/tema01/src/publicKey_RSA.py @@ -0,0 +1,23 @@ +from Crypto.PublicKey import RSA + + +def generate_key_pair(file_name, encryption_key, key_size): + # Generate the RSA key pair + key = RSA.generate(key_size) + + # Write the private key to a file + private_key = key.exportKey("PEM", encryption_key ) + with open(file_name + '_private.pem', 'wb') as f: + f.write(private_key) + + # Write the public key to a file + public_key = key.publickey().exportKey() + with open(file_name + '_public.pem', 'wb') as f: + f.write(public_key) + + +if __name__ == '__main__': + file_name = input('Enter file name to save the key pair: ') + encryption_key = input('Enter encryption key for the private key (press enter for no encryption): ') + key_size = int(input('Enter the key size (in bits): ')) + generate_key_pair(file_name, encryption_key, key_size)