Lab 9_ Data Encryption with OpenSSL
Lab 9_ Data Encryption with OpenSSL
Objective:
Understand the concepts of data encryption and decryption.
TASKS:
Generate public and private key pairs. 2. Encrypt sample data using the public key. 3. Decrypt
the data using the private key. 4. Verify data integrity with SHA-256.
td
Step 1: Install OpenSSL (if not already installed)
For Ubuntu/Debian:
tl
sudo apt update
Pv
sudo apt install openssl
For CentOS/RHEL:
sudo yum install openssl
ng
For macOS:
brew install openssl
ni
ar
Step 2: Generate a Private Key
Le
Extract the public key from the private key and save it as public.pem:
td
Step 1: Create Sample Data File
tl
Create a text file sample.txt with the following content:
Pv
echo "This is a secret message that needs to be encrypted." > sample.txt
ng
Step 2: Encrypt Data Using Public Key
The encrypted.bin file will contain the encrypted data. It won't be human-readable.
AF
Use the private key to decrypt the encrypted.bin file, and save the decrypted data to
decrypted.txt:
cat decrypted.txt
The decrypted data should read:
td
Step 1: Generate a SHA-256 Hash of the Original Data
tl
Create a Hash of the Original sample.txt File:
Pv
Use SHA-256 to generate a hash of the original data:
ng
openssl dgst -sha256 sample.txt
This will generate an output similar to:
SHA256(sample.txt)=
ni
ar
7ae3d7b6247f5bc3dbeb50658295e39f5b6db25bc5cc037fcfcdb1eaece6a476
Le
1.
○
AL
Conclusion
This exercise demonstrates the basics of public-key encryption and data integrity verification.
Let me know if you need any further assistance or clarification on any steps
td
tl
Pv
ng
ni
ar
Le
IE
AF
N
AL