由於問題的標題是自我解釋,請考慮下面的代碼:如何使用openssl解密Java-DES加密的郵件?
private static final String ALGORITHM = "DES";
private static final String MESSAGE = "This is an extremely secret message";
private static final byte[] key = { 0, 1, 2, 3, 4, 5, 6, 7 };
...
// Do encryption
final Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(ENCRYPT_MODE, new SecretKeySpec(key, ALGORITHM));
final byte[] encrypted = cipher.doFinal(MESSAGE.getBytes());
// Copy the encrypted message to a file
final InputStream inputStream = new ByteArrayInputStream(encrypted);
final OutputStream outputStream = new FileOutputStream("___SECRET");
copy(inputStream, outputStream);
現在我試圖解密___SECRET
文件使用以下命令:
openssl enc -d -des -K 0001020304050607 -iv 0 -in ___SECRET -out ___OPEN
導致:
bad decrypt
3073636028:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:539:
剛解密的第一個塊(8個字節),留下其餘部分在垃圾狀態(OEM編碼):
This is MЕ$S6%@╢Т√°ў╝°╢]∙iь
我在做什麼錯,我如何使用openssl
解密加密的消息?
@jww:除了算法中的細微差別之外,11783062是關於使用openssl的默認PBE進行加密的,它實際上是EVP_BytesToKey;這是關於使用密鑰** NOT PBE **進行加密,這是主要的區別。這裏的PBE解決方案完全錯誤。一個**更好的dupe **是http://stackoverflow.com/questions/37354200/blowfish-encrypt-in-java-scala-and-decrypt-in-bash雖然早先羅伯特的答案已經是正確的。 –
OP:請注意,硬件改進使** **不安全**超過20年前不應用於任何安全目的。 _Triple_ DES,由於歷史原因,在Java中被指定爲DESede,但仍然具有穩定的安全性,但其他算法尤其是AES算法更好。 –
@ dave_thompson_085是的,我知道DES的弱點。我的問題是某種逆向工程的結果,所以'openssl'的使用只適用於腳本。謝謝你的意見! –