|
|
Tips No. 654 opensslによるファイルの暗号化opensslコマンドは、OpenSSLの暗号化ライブラリをシェル上から扱うことを可能にします。 各種暗号アルゴリズムによる暗号化/復号化やメッセージ・ダイジェストの計算を行うこと が可能です。 opensslコマンドの書式は次の通りです。 $ openssl コマンド [オプション] [引数] 使用可能なコマンドの一覧は、次の方法で確認することができます。 $ openssl list-standard-commands また、使用可能な暗号化に関するコマンドの一覧は、次の方法で確認することができます。 $ openssl list-cipher-commands 使用可能な暗号アルゴリズムは $ openssl ciphers で確認することができます。 【共通鍵暗号方式】 "AES[Advanced Encryption Standard] 128bits CBCモード"を使用した共通鍵暗号方式に よるファイルの暗号化を行うには、以下のようにします。 $ openssl enc -e -aes-128-cbc -in test.txt -out test.txt.priv enter aes-128-cbc encryption password: Verifying - enter aes-128-cbc encryption password: 出力されたtest.txt.privファイルの内容は暗号化されており内容を参照することができ ません。 これを復号化するには $ openssl enc -d -aes-128-cbc -in test.txt.priv enter aes-128-cbc decryption password: と実行します。正しいパスワードを入力することにより、複合化された内容が出力され ます。 【公開鍵暗号方式】 RSAを使用した公開鍵暗号方式によるファイルの暗号化を行うには、以下のようにします。 まず、秘密鍵を生成します。ここでは、より安全性を高めるためにDES3によって秘密鍵 自体を暗号化しています。 $ openssl genrsa -des3 -out private.pem 続いて、作成した秘密鍵と対となる公開鍵を生成します。 $ openssl rsa -pubout -in private.pem -out public.pem 公開鍵を使って、ファイルを暗号化します。 $ openssl rsautl -encrypt -pubin -inkey public.pem -in test.txt -out test.txt.priv 出力されたtest.txt.privファイルの内容は暗号化されており内容を参照することができ ません。 これを復号化するには % openssl rsautl -decrypt -inkey private.pem -in test.txt.priv と実行します。正しいパスワードを入力することにより、複合化された内容が出力され ます。 【関連情報】 - OpenSSL http://www.openssl.org/
Last modified : Thu Mar 03 JST 2005 # 1
|
Copyright © Turbolinux, Inc..All Right Reserved.

