CATEGORY: COMMANDS

openssl

鍵ペア

秘密鍵

openssl genrsa -out private_key 8192
openssl genrsa -aes256 -out private_key 8192 # with passphrase
chmod 400 private_key

公開鍵

openssl rsa -in private_key -pubout -out public_key

公開鍵で暗号化

openssl rsautl -encrypt -pubin -inkey public_key -in plain.txt -out encrypted

秘密鍵で復号

openssl rsautl -decrypt -inkey private_key -in encrypted -out decrypted.txt

パスワード方式(鍵ファイルなし)

パスフレーズで暗号化するため、鍵ペアは不要。

openssl aes-256-cbc -e -in file -out encrypted
openssl aes-256-cbc -d -in encrypted -out decrypted

-pbkdf2 -iter 付きが安全で、付かない方式は非推奨。

openssl aes-256-cbc -e -pbkdf2 -iter 10 -in makefile  -out encrypted
openssl aes-256-cbc -d -pbkdf2 -iter 10 -in encrypted -out decrypted.txt