LoginSignup
34
34

More than 3 years have passed since last update.

OpenSSLでファイルの暗号化・復号化するための備忘録

Last updated at Posted at 2016-12-10

はじめに

opensslコマンドは以下の3つの分類されています。
Cipher commandを使ってファイルの暗号化・復号をやります。

  • Standard commands
  • Message Digest commands
  • Cipher command

基本的な使い方

encサブコマンドを使って暗号化・復号します。

入力ファイルを暗号化・復号し出力ファイルに出したいケースが多いと思いますが、その場合はそれぞれ-in,-outにファイルパスを渡してあげます。

暗号化の場合、-eを復号の場合は-dをつけます。

// 暗号化
$ openssl enc -e <CipherType> -in <InputFile>  -out <OutputFile>
// 復号
$ openssl enc -d <CipherType> -in <InputFile>  -out <OutputFile>

また、CipherType(aes-256-cbcなど)を以下のようにサブコマンドの位置に書いても暗号化・復号してくれるみたいです。

$ openssl aes-256-cbc -e -in <InputFile> -out <OutputFile>
$ openssl aes-256-cbc -d -in <InputFile> -out <OutputFile>

パスワードの指定方法

タイプ
stdin 標準入力から指定
pass コマンドラインで指定
file ファイルから指定
env 環境変数から指定
fd ファイルディスクリプタから指定
  • コマンドラインからパスワードを指定する場合
$ openssl aes-256-cbc -e -in in_sample.txt -out out_sample.txt -pass pass:hoge
  • ファイルからパスワードを指定する場合
$ openssl aes-256-cbc -e -in in_sample.txt -out out_sample.txt -pass file:./password.txt

参考

34
34
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
34