0% found this document useful (0 votes)
5 views

Hands On Command

This document provides examples of using openssl to encrypt and decrypt files using AES, RSA, Diffie-Hellman key exchange, hashing, digital signatures with RSA and ECDSA.

Uploaded by

hanoi6
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Hands On Command

This document provides examples of using openssl to encrypt and decrypt files using AES, RSA, Diffie-Hellman key exchange, hashing, digital signatures with RSA and ECDSA.

Uploaded by

hanoi6
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/// AES openssl

hexdump Example_AA_BB.bin
openssl enc -aes-128-ecb -k deadbeefdeadbeef -nosalt -nopad -in Example_AA_BB.bin
-out Example_AA_BB.enc
hexdump Example_AA_BB.enc
openssl enc -d -aes-128-ecb -k deadbeefdeadbeef -nosalt -nopad -in
Example_AA_BB.enc -out Example_AA_BB_clear.bin
hexdump Example_AA_BB_clear.bin

hexdump Example_AA_BB.bin
openssl enc -aes-128-cbc -k deadbeefdeadbeef -iv deaddead -nosalt -nopad -in
Example_AA_BB.bin -out Example_AA_BB_cbc.enc
hexdump Example_AA_BB_cbc.enc
openssl enc -d -aes-128-cbc -k deadbeefdeadbeef -iv deaddead -nosalt -nopad -in
Example_AA_BB_cbc.enc -out Example_AA_BB_clear_cbc.bin
hexdump Example_AA_BB_clear_cbc.bin

/// RSA openssl


openssl genrsa -out MyPrivKey.pem 2048
openssl rsa -in MyPrivKey.pem -pubout -out MyPubKey.pem
openssl rsa -in MyPrivKey.pem -text
openssl rsa -in MyPubKey.pem -text -pubin

openssl rsautl -encrypt -inkey MyPubKey.pem -pubin -in Example_AA_BB.bin -out


Example_AA_BB_rsa.enc
openssl rsautl -decrypt -inkey MyPrivKey.pem -in Example_AA_BB_rsa.enc -out
Example_AA_BB_clear_rsa.bin
hexdump Example_AA_BB_rsa.enc
hexdump Example_AA_BB_clear_rsa.bin

//Diffie Hellman openssl


openssl genpkey -genparam -algorithm DH -out dhp.pem
openssl pkeyparam -in dhp.pem -text
openssl genpkey -paramfile dhp.pem -out dhkey_Alice.pem
openssl pkey -in dhkey_Alice.pem -text -noout
openssl pkey -in dhkey_Alice.pem -pubout -out dhpub_Alice.pem
openssl pkey -pubin -in dhpub_Alice.pem -text

openssl genpkey -paramfile dhp.pem -out dhkey_Bob.pem


openssl pkey -in dhkey_Bob.pem -text -noout
openssl pkey -in dhkey_Bob.pem -pubout -out dhpub_Bob.pem
openssl pkey -pubin -in dhpub_Bob.pem -text

openssl pkeyutl -derive -inkey dhkey_Alice.pem -peerkey dhpub_Bob.pem -out


secret1.bin
openssl pkeyutl -derive -inkey dhkey_Bob.pem -peerkey dhpub_Alice.pem -out
secret2.bin
hexdump secret1.bin
hexdump secret2.bin

// Hash
openssl dgst -md5 Example_AA_BB.bin
openssl dgst -md5 Example_AA_BB_1bit_modified.bin
openssl dgst -sha1 Example_AA_BB.bin
openssl dgst -sha1 Example_AA_BB_1bit_modified.bin
openssl dgst -sha256 Example_AA_BB.bin
openssl dgst -sha256 Example_AA_BB_1bit_modified.bin
openssl dgst -sha512 Example_AA_BB.bin
openssl dgst -sha512 Example_AA_BB_1bit_modified.bin

// RSA signature
echo abcdefghijklmnopqrstuvwxyz > myfile.txt
openssl dgst -sha256 -sign MyPrivKey.pem -out signature.bin myfile.txt
openssl dgst -sha256 -verify MyPubKey.pem -signature signature.bin myfile.txt
echo aacdefghijklmnopqrstuvwxyz > myfile2.txt
openssl dgst -sha256 -verify MyPubKey.pem -signature signature.bin myfile2.txt

//ECDSA
openssl ecparam -list_curves
openssl ecparam -param_enc explicit -conv_form uncompressed -text -noout -no_seed -
name prime192v1
openssl ecparam -name prime192v1 -genkey -out MyECCKey.pem
openssl ec -in MyECCKey.pem -pubout -out MyECCPubKey.pem
openssl dgst -sha256 -sign MyECCKey.pem < myfile.txt > signature.bin
openssl dgst -sha256 -verify MyECCPubKey.pem -signature signature.bin < myfile.txt

You might also like