實驗目的:掌握常見的密碼學演算法應用,包含des aes md5 rsa等
實驗環境:一臺 Centos 7.2 已經安裝 openssl 組件
實驗原理:openssl是Linux內置的一款開源工具,實作了常見的密碼演算法與應用,通過openssl操作,完成各種密碼演算法的應用,
實驗步驟:
創建一個檔案,用于被加密,檔案內容為12345,檔案名為test.txt

對稱加密
使用 rc4 加解密
加密
openssl enc -e -rc4 -in test.txt -out test_rc4.enc
輸入加密的密碼

解密
openssl enc -d -rc4 -in test_rc4.enc -out test_rc4.dm
輸入解密密碼

使用 AES 加解密
openssl enc -e -aes-128-cbc -a -salt -in test.txt -out test_aes128.enc

解密
openssl enc -d -aes-128-cbc -a -salt -in test_aes128.enc -out test_aes128.d

使用 3DES 加解密
加密
openssl enc -e -des3 -a -salt -in test.txt -out test_des3.enc

解密
openssl enc -d -des3 -a -salt -in test_des3.enc -out test_des3.d

非對稱加密
RSA加解密碼
生成RSA密鑰對
openssl genrsa -out rsa.key 1024

匯出公鑰
openssl rsa -in rsa.key -pubout -out rsa_pub.key

使用公鑰加密檔案
openssl rsautl -encrypt -in test.txt -inkey rsa_pub.key -pubin -out test_rsa.enc

使用私解解密檔案
openssl rsautl -decrypt -in test_rsa.enc -inkey rsa.key -out test_rsa.c

使用公鑰解密報錯
openssl rsautl -decrypt -in test_rsa.enc -inkey rsa_pub.key -out test_rsa.c

通過實驗的openssl 實作對稱加解密與非對稱加解密兩種基線的加解密功能,
思考對稱與非對稱加解密碼的流程上有何不同?為什么?
對稱加密兩端都是一個密碼 安全性不高
非對稱加密產生兩個不同的密鑰 加解密都需要不同的密鑰安全性更高
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/375207.html
標籤:其他
