Sharing Encrypted Files Using OpenSSL

· demo's blog


I was curious how I would accomplish this and found (this)[https://opensource.com/article/21/4/encryption-decryption-openssl] handy source.

Here are the relevant commands from the blog post

 1openssl genrsa -aes128 -out alice_private.pem 1024
 2ls -l alice_private.pem 
 3openssl genrsa -aes128 -out bob_private.pem 1024
 4ls -l bob_private.pem 
 5openssl rsa -in alice_private.pem -noout -text
 6openssl rsa -in alice_private.pem -pubout > alice_public.pem
 7ls -l *.pem
 8openssl rsa -in alice_public.pem -pubin -text -noout
 9openssl rsa -in bob_private.pem -pubout > bob_public.pem
10ls -l *.pem
11scp alice_public.pem bob@bob-machine-or-ip:/path/
12scp bob_public.pem alice@alice-machine-or-ip:/path/
13ls -l bob_public.pem 
14ls -l alice_public.pem 
15echo "vim or emacs ?" > top_secret.txt
16cat top_secret.txt 
17openssl rsautl -encrypt -inkey bob_public.pem -pubin -in top_secret.txt -out top_secret.enc
18ls -l top_secret.*
19cat top_secret.txt 
20cat top_secret.enc
21hexdump -C ./top_secret.enc 
22file top_secret.enc 
23rm -f top_secret.txt 
24scp top_secret.enc bob@bob-machine-or-ip:/path/
25ls -l top_secret.enc 
26cat top_secret.enc 
27hexdump -C top_secret.enc 
28openssl rsautl -decrypt -inkey bob_private.pem -in top_secret.enc > top_secret.txt
29ls -l top_secret.txt 
30cat top_secret.txt 
31echo "nano for life" > reply_secret.txt
32cat reply_secret.txt 
33openssl rsautl -encrypt -inkey alice_public.pem -pubin -in reply_secret.txt -out reply_secret.enc
34ls -l reply_secret.enc 
35cat reply_secret.enc 
36hexdump -C ./reply_secret.enc 
37scp reply_secret.enc alice@alice-machine-or-ip:/path/
38ls -l reply_secret.enc 
39cat reply_secret.enc 
40openssl rsautl -decrypt -inkey alice_private.pem -in reply_secret.enc > reply_secret.txt
41ls -l reply_secret.txt 
42cat reply_secret.txt