{ "info": { "author": "Nathaniel Knous", "author_email": "nsk89@live.com", "bugtrack_url": null, "classifiers": [], "description": "# netcrypt\n\n
socket transmission and encryption protocols
\nproject is intended to simplify socket encryption and common server/client communication tasks
\n\n## installation\n\nclone this repository or simply your favorite way over pip:
\n\n```\npython3 -m pip install netcrypt\n```\n\n## how it works\n\nthis project doesn't incorporate basic server/client functions besides communication, though that may change in the future. the current state of the project mainly deals with sending data, including files, over sockets securely. data to be sent is first encrypted using AES. the AES key and init vector are then encrypted with a RSA cipher from the public key set from the exchanging socket connection. the data(message) then creates a hash verification for use on decryption to verify data itegrity. \n
\n
\nkey, init vector, data verification hash and data are then stored in a dictionary to be dumped into a serialized bytes object. the serialized object is then structured into internet byte order and length of object is stored in the first four bytes of transmission. on receive, the first four bytes are read from the stream retrieving the stream length, the remainder of the stream is collected and read in based off the length. the process goes in reverse from there.\n
\n
all socket data encryption is done in communication.py which methods use cryptography.py(based off PyCryptodome ciphers).\n\n## getting started\n \n
create a server stream encryption object, this example we'll use crypto_traffic:
\n\n```\nfrom netcrypt.communication import ServerProtocol\n\n\ncrypto_traffic = ServerProtocol()\n```\nto start encrypted communication public keys must be exchanged, exchange the public keys and store the clients key:
\n\n```\nclient_public_key = crypto_traffic.public_key_exchange()\n```\nto send or receive data, the public key needs to be set first. in this case we're sending:
\n\n```\ncrypto_traffic.set_public_key(client_public_key)\n\nmessage = b'Welcome to the server!'\ncrypto_traffic.send_crypto_stream(conn, message) \n```\nto receive the message client side:
\n\n```\nserver_message = crypto_traffic.recv_crypto_stream(sock)\n```\nsending a file from server to client, in this case we have testFile.txt stored in cwd:
\n\n```\ncrypto_traffic.send_file(conn, 'testFile.txt')\n```\nto receive above file client side and store in cwd:
\n\n```\ncrypto_traffic.recv_file(sock)\n```\na socks socket will be returned on the enable_tor() call. the returned socket object is used in place of the typical socket
object and inherits its functionality. route client through the tor network:
create an instance of CryptoProtocol:
\n\n```\nfrom netcrypt.cryptography import CryptoProtocol\n\n\ncrypto_worker = CryptoProtocol()\n```\n\ngenerate random keys:
\n\n```\naes_key = crypto_worker.generate_key(32)\ninit_vect = crypto_worker.generate_key(16)\n```\n\nencrypt data with AES cipher:
\n\n```\ndata = 'hello, world'\naes_key = crypto_worker.generate_key(32)\ninit_vect = crypto_worker.genreate_key(16)\nencrypted_data = crypto_worker.encrypt(aes_key, init_vect, data)\n```\n\ndecrypt data with AES cipher:
\n\n```\ndecrypted_data = crypto_worker.decrypt(aes_key, init_vect, encrypted_data)\n```\n\ncreate RSA private key and return public key:
\n\n```\nmy_public_key = crypto_worker.start_rsa(4096)\n```\n\nencrypt AES encryption key with RSA public key:
\n\n```\nencrypted_aes_key = crypto_worker.rsa_encrypt(my_public_key, aes_key)\n```\n\ndecrypt AES encryption key with RSA private key:
\n\n```\ndecrypted_aes_key = crypto_worker.rsa_decrypt(encrypted_aes_key)\n```\n\n