LoginSignup
2
0

More than 5 years have passed since last update.

Opensslを利用した暗号化データ送受信

Last updated at Posted at 2016-12-20

Opensslを利用した暗号化データ送受信

利用するファイル

  • data.txt - data file to be exchanged
  • key.bin - random key
  • private.pem - private key
  • private.pem.nopass - private key without pass phrase
  • public.pem - public key

キーペアを作成

openssl genrsa -des3 -out private.pem 2048
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
openssl rsa -in private.pem -out private.pem.nopass

送信側

1) ランダム鍵を作成

openssl rand -base64 128 -out key.bin

2) ランダム鍵を利用し送信ファイルを暗号化する

openssl enc -aes-256-cbc -salt -in data.txt -out data.txt.enc -pass file:./key.bin

3) 公開鍵でランダム鍵を暗号化

openssl rsautl -encrypt -inkey public.pem -pubin -in key.bin -out key.bin.enc

4) 暗号化したファイルとランダム鍵を受信者へ送付

  • data.txt.enc
  • key.bin.enc

受信側

1) 秘密鍵でランダム鍵を復号

パスフレーズあり:

openssl rsautl -decrypt -inkey private.pem -in key.bin.enc -out key.bin.dec

パスフレーズなし:

openssl rsautl -decrypt -inkey private.pem.nopass -in key.bin.enc -out key.bin.dec

2) ランダム鍵で暗号化したファイルを復号

openssl enc -d -aes-256-cbc -in data.txt.enc -out data.txt.dec -pass file:./key.bin.dec
2
0
0

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
2
0