
GPGを使用してファイルを作成し、対称的に暗号化しました。
touch test.txt && echo 'test' >> test.txt
gpg --output test.txt --symmetric test.txt
しかし、今はそれを解読する方法がわからず、驚くべきことにオンラインで例を見つけることができません。私が試したことは次のとおりです。
$ gpg --decrypt test.txt
gpg: AES encrypted data
gpg: encrypted with 1 passphrase
$ gpg --symmetric --decrypt test.txt
gpg: conflicting commands
$ gpg --passphrase --decrypt test.txt
gpg: no valid OpenPGP data found.
gpg: decrypt_message failed: Unknown system error
$ gpg --decrypt --output test_decrypted.txt test.txt
gpg: no valid OpenPGP data found.
gpg: decrypt_message failed: Unknown system error
私は何が間違っていましたか?
答え1
正しいコマンドは
gpg --decrypt test.txt
ただし、gpg
入力を読み取る前に出力が上書きされるため、test.txt
元のコンテンツが失われます。
別のファイルで暗号化する必要があります。
gpg --output test.gpg --symmetric test.txt
答え2
使い方は--symmetric
混乱するほど非対称のようです。
- 暗号化に使用する必要
--symmetric
がありますが、 - 解毒のため
--decrypt
。
また、結果を別のファイルに出力します。
完全に再現可能な例(バッチモードを使用し、メッセージは表示されません):
#!/bin/bash
echo "Some important content" > a.txt
[ -f a.txt.gpg ] && rm a.txt.gpg
[ -f b.txt ] && rm b.txt
echo "secret" | gpg --batch --passphrase-fd 0 --output a.txt.gpg --symmetric a.txt
echo "secret" | gpg --batch --passphrase-fd 0 --output b.txt --decrypt a.txt.gpg
echo "------------------------- a.txt"
cat a.txt
echo "------------------------- b.txt"
cat b.txt
diff a.txt b.txt && echo "Files have the same content"