|
~ To be, or not to be, or to ask someone to be. ~ null-i.net |
| Linux/gpg | |||||||||||||||||
|
gpg (GNU Privacy Guard)(2015-01-13) ファイルの暗号化、復号化などできるコマンドです。 ファイルの暗号化、復号化†
まず、とりあえず実行したら、エラーになりました。 can't connect to `/home/xxxx/.gnupg/S.gpg-agent': No such file or directory どうやら、gpgを使うには事前にエージェントが上がっていないといけない模様。 $ gpg-agent --daemon --use-standard-socket まず、暗号化から。 $ cat IROHA.txt
いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす!
$ gpg -c IROHA.txt
┌──────────────────────────┐
│ Enter passphrase │
│ │
│ │
│ Passphrase ****___________________________________ │
│ │
│ <OK> <Cancel> │
└──────────────────────────┘
いきなり対話式になったので驚きましたが、二回パスワードを入力すると暗号化ファイルができます。 $ cat -v IROHA.txt.gpg M-^L^M^D^B^C^BM-)M-~aM-a:ChMM-KM-(まぁ、バイナリで読めないので省略しますが) $ ls -l IROHA.txt* -rw-rw-r-- 1 xxxx xxxx 143 Jan 14 19:58 IROHA.txt -rw-rw-r-- 1 xxxx xxxx 162 Jan 14 19:58 IROHA.txt.gpg 次に復号します。 $ gpg -d IROHA.txt.gpg gpg: 3DES encrypted data gpg: encrypted with 1 passphrase いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす! gpg: WARNING: message was not integrity protected 最後のWARNINGは「メッセージの完全性は保護されていません」というもの。 $ pkill gpg-agent
$ gpg -d IROHA.txt.gpg
┌──────────────────────────┐
│ Enter passphrase │
│ │
│ │
│ Passphrase ****___________________________________ │
│ │
│ <OK> <Cancel> │
└──────────────────────────┘
gpg: 3DES encrypted data
can't connect to `/home/xxxx/.gnupg/S.gpg-agent': No such file or directory
gpg: encrypted with 1 passphrase
いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす!
gpg: WARNING: message was not integrity protected
なんか、エージェントに接続できないメッセージは出ましたが 鍵の生成†
こちらはgpg-agentの起動は不要っぽい。とりあえず実行。 $ gpg --gen-key
gpg (GnuPG) 2.0.14; Copyright (C) 2009 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection? ←そのままEnter。暗号化方式の選択。
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) ←そのままEnter。鍵の長さ。
Requested keysize is 2048 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) ←そのままEnter。有効期限で、0は無期限。
Key does not expire at all
Is this correct? (y/N) y ←"y" でEnter
GnuPG needs to construct a user ID to identify your key.
Real name: Jhon Smith ←通称ハンニバル。奇襲戦法と変装の名人。
Email address: aaa@example.com ←てきとう
Comment: test ←テスト
You selected this USER-ID:
"Jhon Smith (test) <aaa@example.com>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O ←"O"でEnter
You need a Passphrase to protect your secret key.
(ここでパスワード入力画面に切り替わるので、入力する)
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
・・・あれ?固まったぞ? 別のウィンドウで接続して、こんな感じで待つ while :; do yes | head -99999999 > yes.txt; rm yes.txt; echo -n .; done 席を外したので分かりませんが、結局30分くらいかかった?長いです。 gpg: /home/xxxx/.gnupg/trustdb.gpg: trustdb created
gpg: key 4DA96D64 marked as ultimately trusted
public and secret key created and signed.
gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
pub 2048R/4DA96D64 2015-01-21
Key fingerprint = F991 3FD8 7982 6E50 4A97 616E FAB0 5736 4DA9 6D64
uid Jhon Smith (test) <aaa@example.com>
sub 2048R/351FC52E 2015-01-21
で、 ~/.gnupg/ の下に色々更新されているようです。 鍵リングの表示†
自分の所有している鍵のセット(キーリング)を表示できます。 $ gpg -K /home/xxxx/.gnupg/secring.gpg ------------------------------- sec 2048R/4DA96D64 2015-01-21 uid Jhon Smith (test) <aaa@example.com> ssb 2048R/351FC52E 2015-01-21 $ gpg -k /home/xxxx/.gnupg/pubring.gpg ------------------------------- pub 2048R/4DA96D64 2015-01-21 uid Jhon Smith (test) <aaa@example.com> sub 2048R/351FC52E 2015-01-21 秘密鍵がsecで公開鍵がpub、2048ビット長のRSAで、鍵IDが4DA96D64、製造日、ユーザ名と続きます。 $ gpg --list-sigs /home/xxxx/.gnupg/pubring.gpg ------------------------------- pub 2048R/4DA96D64 2015-01-21 uid Jhon Smith (test) <aaa@example.com> sig 3 4DA96D64 2015-01-21 Jhon Smith (test) <aaa@example.com> sub 2048R/351FC52E 2015-01-21 sig 4DA96D64 2015-01-21 Jhon Smith (test) <aaa@example.com> sigが署名部分で、署名IDと署名日、署名者と続きます。 $ gpg --check-sigs /home/xxxx/.gnupg/pubring.gpg ------------------------------- pub 2048R/4DA96D64 2015-01-21 uid Jhon Smith (test) <aaa@example.com> sig!3 4DA96D64 2015-01-21 Jhon Smith (test) <aaa@example.com> sub 2048R/351FC52E 2015-01-21 sig! 4DA96D64 2015-01-21 Jhon Smith (test) <aaa@example.com> sig!の「!」は検証が成功、 マニュアルが英語なので(たいした内容ではなさそうですが)読むのがしんどいです… |
|
||||||||||||||||