Rivest Shamir Adleman (RSA)
A public-key cryptosystem that uses a pair of mathematically related keys: a public key for encryption and a private key for decryption. It was developed in 1977 by Ron Rivest, Adi Shamir, and Leonard Adleman and remains one of the most widely used asymmetric encryption algorithms in the world.RSA relies on the mathematical difficulty of factoring large prime numbers to ensure security. While the public key can be freely shared to encrypt messages, only the holder of the corresponding private key can decrypt the ciphertext. This allows secure communication between parties without the need to share a secret key in advance.
echo “test” > input.txt # Create a file named input.txt containing the text “test”
echo "test" > input.txt
openssl # an open-source cryptography toolkit
genrsa # generates an RSA private key
-out private.key # output file for private key
2048 # key size in bits (secure for most uses)
openssl genrsa -out private.key 2048
openssl # an open-source cryptography toolkit
rsa # RSA key utility
-in private.key # input private key
-pubout # output the corresponding public key
-out public.key # output file for public key
openssl rsa -in private.key -pubout -out public.key
openssl # an open-source cryptography toolkit
pkeyutl # utility for public/private key operations
-encrypt # encrypt mode
-pubin # input key is a public key
-inkey public.key # the public key used for encryption
-in input.txt # plaintext input file
-out encrypted.txt # output ciphertext file
openssl pkeyutl -encrypt -pubin -inkey public.key -in input.txt -out encrypted.txt
openssl # an open-source cryptography toolkit
-decrypt # decrypt mode
-inkey private.key # the private key used for decryption
-in encrypted.txt # input ciphertext file
-out decrypted.txt # output plaintext file
openssl pkeyutl -decrypt -inkey private.key -in encrypted.txt -out decrypted.txt
cat decrypted.txt # Display the decrypted file contents
cat decrypted.txt