「OpenSSLコマンドを用いた公開鍵暗号」の版間の差分

提供: セキュリティ
移動: 案内検索
(ページの作成:「<!-- vim: filetype=mediawiki --> __TOC__ == 概要 == ここでは、OpenSSLコマンドで、RSA アルゴリズムを用いて、データを公開鍵暗...」)
 
行8: 行8:
  
 
ここでは、[[OpenSSL]]コマンドで、[[RSA]] アルゴリズムを用いて、データを公開鍵暗号方式で暗号化をします。
 
ここでは、[[OpenSSL]]コマンドで、[[RSA]] アルゴリズムを用いて、データを公開鍵暗号方式で暗号化をします。
 +
 +
[[共通鍵暗号]]の場合は、[[OpenSSLコマンドを用いた共通鍵暗号]]をご参照下さい。
  
 
== インストール ==
 
== インストール ==
行104: 行106:
 
== 関連項目 ==
 
== 関連項目 ==
  
 +
* [[OpenSSLコマンドを用いた共通鍵暗号]]
 
* [[OpenSSL]]
 
* [[OpenSSL]]
 
* [[公開鍵暗号]]
 
* [[公開鍵暗号]]
 
* [[RSA]]
 
* [[RSA]]

2013年1月19日 (土) 14:25時点における版


概要

ここでは、OpenSSLコマンドで、RSA アルゴリズムを用いて、データを公開鍵暗号方式で暗号化をします。

共通鍵暗号の場合は、OpenSSLコマンドを用いた共通鍵暗号をご参照下さい。

インストール

使い方

秘密鍵の作成

秘密鍵を作成します。

% openssl genrsa -out private.pem 2048
Generating RSA private key, 2048 bit long modulus
..........................................+++
............................................................................................................+++
e is 65537 (0x10001)

暗号化した秘密鍵を作成する場合は、以下の通りです。 秘密鍵AES256 で暗号化します。

% openssl genrsa -out private_secure.pem -aes256 2048
Generating RSA private key, 2048 bit long modulus
............................+++
.....................+++
e is 65537 (0x10001)
Enter pass phrase for private_secure.pem:
Verifying - Enter pass phrase for private_secure.pem:

公開鍵の作成

秘密鍵から公開鍵を作成します。

% openssl rsa -in private.pem -pubout -out public.pem
writing RSA key

ファイルの準備

暗号化するファイルを準備します。

echo 'hoge'> file.txt

このファイルは、なんでも構いません。

暗号化

file.txt を暗号化します。暗号化されたファイルは、 file.encrypted です。

openssl rsautl -encrypt -inkey public.pem -pubin -in file.txt -out file.encrypted

作成されたデータは、以下の通りです。バイナリデータのため16進でダンプしています。

% hexdump file.encrypted
0000000 2c10 3952 f711 02d2 92ba 81ff 97d1 7ad1
0000010 8fef 6e42 d081 1c77 ba96 0808 62ee bed9
0000020 d1c5 9163 6c80 211f b20d ab2f 7459 313c
0000030 1f4c 829b 4a5a 5539 4782 34ef 95e9 423c
0000040 115f 1ac7 fc5b dd36 7378 d85f 6895 7fc6
0000050 016e bf94 4ad5 c5eb 3d17 742c 2cd3 b0d8
0000060 5412 3514 80c6 b6e2 028b efb2 e447 f78a
0000070 6cef 01dc 1d13 935b 565d ae07 9152 6b4d
0000080 4909 5c0a 1bc2 15f7 a631 4863 30fc d4e8
0000090 1cad e50d 88ef 8aa9 911d b90d a95b 3187
00000a0 343d 17cf 86ea d189 faed 264b 9fbc 832b
00000b0 e89a 414b 7878 5969 364b 47c2 b7a0 1409
00000c0 1a05 d316 032a 04b0 956e c5f2 17bb 16e3
00000d0 a55d cfb8 96fc 0da5 d5f8 088c a8dc 38be
00000e0 97f4 b0fb b4ed 8e47 6b3a 3220 a297 9f07
00000f0 db6a c619 f514 1c84 d871 63af eed9 b2d3
0000100

復号化

暗号化されたファイルを復号化します。

% openssl rsautl -decrypt -inkey private.pem -in file.encrypted -out file.decrypted
% cat file.decrypted
hoge
%

関連項目