PyRSA is a command line utility that allows users to digitally encrypt and sign messages using the public key encryption scheme, RSA. There are three basic functions that PyRSA performs: encryption, decryption, and key generation.
1. Generate a public and private key. In this example, we will specify a key of length 1024 bits. Allow several seconds of CPU time for the generation of the keys.
pyrsa.py -g 1024 Enter file identifier (i.e. first name): brandon
2. Now the files
are in the current directory. Next place the text we want to encrypt in a text file.
echo "The sky above the port was the color of television, tuned to a dead channel." > message.txt
3. Encrypt the message using the public key and redirect the output to a text file.
pyrsa.py -e message.txt -k brandon_publicKey.txt > ciphertext.txt
4. At this point the file ciphertext.txt contains the encrypted message. The file can safely be sent to a recipient, i.e. as an email attachment, the contents utterly unreadable to anyone without the private key.
cat ciphertext.txt 32464047998704731086703458860763720628883125201 840735448292781611869424600546740055592235111171870058664751326891 416030992911165222195048303846516331939189036032662981573683210672 785053735077400433222553780571914729993485153779710689497701348386 214277988780913721453283666357504772556433129612632786845350983
5. Next we will assume the message has been sent to the individual who possesses the corresponding private key and he wants to decrypt the message.
pyrsa.py -d ciphertext.txt -k brandon_privateKey.txt Decrypted text: The sky above the port was the color of television, tuned to a dead channel.