2013-07-07 61 views
1

我試圖加密一個簡單的字符串「Hello world」。使用OpenSSL命令行工具。我已經試過同時使用Base64和二進制文件都加密。但我得到一些無益的錯誤。OpenSSL「錯誤讀取輸入文件」和「壞的幻數」

$ "Hello world." > plain.txt 
$ openssl enc -aes-128-ecb -e -base64 -in plain.txt > enc.txt 
enter aes-128-ecb encryption password: 
Verifying - enter aes-128-ecb encryption password: 
$ cat enc.txt 
U2FsdGVkX18ZoAY34fL2aMO0Bu5AJnewemhfiBmSL1IJujqOtpJm7V0C+Tt83egJ 
$ openssl enc -aes-128-ecb -d -base64 -in enc.txt > out.txt 
enter aes-128-ecb decryption password: 
error reading input file 

然後我嘗試二進制

$ "Hello world." > plain.txt 
$ openssl enc -aes-128-ecb -e -in plain.txt > enc.bin 
enter aes-128-ecb encryption password: 
Verifying - enter aes-128-ecb encryption password: 
$ openssl enc -aes-128-ecb -d -in enc.bin > out.txt 
enter aes-128-ecb decryption password: 
bad magic number 

回答

2

馬克,我看不出有什麼毛病你的命令。他們在我的系統上工作得很好。所以這個問題一定在別的地方。

我建議嘗試不同的安裝/版本的OpenSSL或不同的系統。

+0

是的,我試圖在Ubuntu和有效。它在我的Windows 7系統上壞掉了。該版本是被包裝使用Git OpenSSL的。 – Mark

+0

Mark,您可以嘗試的另一個Windows版本的OpenSSL是[slproweb.com](http://slproweb.com/products/Win32OpenSSL.html)。 – gtrig

0

我想也許你的命令沒有錯,因爲現在我遇到了同樣的問題。 TXT文件無法自動更改爲第二行,因此,需要在密文末尾輸入「Enter」並保存文本。然後,您可以再次輸入您的命令。

$ OpenSSL的ENC - 脫-d -base64 -in atxt> a2.txt

進入DES-CBC解密密碼:

enter image description here