密碼學筆記
  • Introduction
  • 數論相關
  • 大數轉換
  • Big Endian & small Endian
  • MD5
  • RSA
  • DSA
  • AES
  • SHA256
  • RIPEMD
  • ECDSA & ECDH
  • OpenSSL 實用指令
  • Crypto module
  • Byte Padding
Powered by GitBook
On this page
  • 查看版本
  • 查看所有可用指令
  • 查看所有可以使用的指令標籤
  • 查看所有可用的加密演算法
  • 測試加密執行速度
  • 測試遠端 https 連線效率
  • 產生自己簽發的證書
  • 下載其他網站的證書
  • 產生檔案的雜湊值
  • 產生對應的 base64 編碼
  • 直接在 Terminal 用 AES 加密檔案
  • 產生 RSA Public key 與 Private Key
  • 參考資料

Was this helpful?

OpenSSL 實用指令

OpenSSL 內建 Linux, Mac 等系統中,可以使用一些指令協助我們

查看版本

openssl version -a

查看所有可用指令

openssl help

查看所有可以使用的指令標籤

openssl dgst -h

查看所有可用的加密演算法

openssl ciphers -v

測試加密執行速度

openssl speed

測試遠端 https 連線效率

openssl s_time -connect remote.host:443 -www /test.html -new

產生自己簽發的證書

openssl req \
  -x509 -nodes -days 365 -sha256 \
  -newkey rsa:2048 -keyout mycert.pem -out mycert.pem

下載其他網站的證書

echo -n | openssl s_client -connect $HOST:$PORTNUMBER -servername $SERVERNAME \
    | openssl x509 > /tmp/$SERVERNAME.cert

產生檔案的雜湊值

# MD5 digest
openssl dgst -md5 filename

# SHA1 digest
openssl dgst -sha1 filename

# SHA256 digest
openssl dgst -sha256 filename

產生對應的 base64 編碼

# 把 file.txt 轉 base64 後寫入到 terminal
openssl enc -base64 -in file.txt

# 寫入到 file.txt.enc
openssl enc -base64 -in file.txt -out file.txt.enc

# 直接在 terminal 輸出
$ echo "encode me" | openssl enc -base64

直接在 Terminal 用 AES 加密檔案

輸入後會要你打上密碼

openssl enc -aes-256-cbc -salt -in test.txt -out file.enc

解密

openssl enc -d -aes-256-cbc -in file.enc

除了 AES 外可用以下指令查詢所有可用的加密算法

openssl list-cipher-commands

產生 RSA Public key 與 Private Key

先產生 2040 bits 的私鑰

openssl genrsa -out mykey.pem 2048

從私鑰再產生公鑰

openssl rsa -in mykey.pem -pubout

參考資料

PreviousECDSA & ECDHNextCrypto module

Last updated 2 years ago

Was this helpful?

Logohow to download the ssl certificate from a website?Server Fault
Logo/docs/manmaster/man1/index.html
LogoOpenSSL Essentials: Working with SSL Certificates, Private Keys and CSRs | DigitalOcean
LogoOpenSSL Quick Reference Guide | DigiCert.com
LogoOpenSSL Command-Line HOWTO