(1) generate an RSA private/public key pair.
(2) encrypt and decrypt a message using the private/public keys generated.
Some explanations:
(1) Generate an RSA private key first. The public key can then be obtained from the private key.
(2) Use different keys of the same key pair for encrypting/decrypting. For example, encrypt a message with the public key and then decrypt the encrypted message with the private A cryptosystem using this public-private key mechanism is known as asymmetric because different keys are used for encrypting/decrypting.
The following terminal commands have been tested on a Raspberry Pi and a Mac.
For Raspberry Pi, commands may need an extra sudo word in front of openssl or executed in the desktop folder.
1. Generate an RSA private and public key pair in PEM format:
Generate a 1024-bit private key:
openssl genrsa -out private_key.pem 1024
Obtain a public key from the private key:
openssl rsa -in private_key.pem -pubout -out public_key.pem
2. Create a message.txt file and edit its content:
sudo nano message.txt
3. Encrypt message.txt with public_key.pem using this command:
openssl rsautl -in message.txt -encrypt -pubin -inkey public_key.pem > encrypted.txt
4. Decrypt encrypted.txt with private_key.pem using this command:
openssl rsautl -in encrypted.txt -decrypt -inkey private_key.pem
References:
Raspberry Pi / Linux:
Encrypt/decrypt a string with RSA public/private keys in PHP
Encrypt/decrypt a string with RSA public/private PEM files using Python
Sending an RSA encrypted message from client to Python socket server
iOS:
Encrypt/decrypt a string with RSA public/private keys in Swift
Encrypt/decrypt a string with public/private keys imported from PEM files
Go back to Communication between iOS device (Client) and Raspberry Pi (Server)
References:
Raspberry Pi / Linux:
Encrypt/decrypt a string with RSA public/private keys in PHP
Encrypt/decrypt a string with RSA public/private PEM files using Python
Sending an RSA encrypted message from client to Python socket server
iOS:
Encrypt/decrypt a string with RSA public/private keys in Swift
Encrypt/decrypt a string with public/private keys imported from PEM files
Go back to Communication between iOS device (Client) and Raspberry Pi (Server)
No comments:
Post a Comment