0
我在加密和解密兩個套接字之間的數據流時遇到了問題。從套接字創建密碼流時發生應用程序死鎖
ObjectInputStream oIn = new ObjectInputStream(new FileInputStream(new File("key")));
SecretKeySpec spec = (SecretKeySpec) oIn.readObject();
//'key' file was saved previously
Cipher cEncrypt = Cipher.getInstance("AES");
cEncrypt.init(Cipher.ENCRYPT_MODE, spec);
Cipher cDecrypt = Cipher.getInstance("AES");
cDecrypt.init(Cipher.DECRYPT_MODE, spec);
//should have no problems here, I tried the ciphers out by encoding and decoding a String, works fine
ObjectOutputStream objectOutputStream= new ObjectOutputStream(new CipherOutputStream(socket.getOutputStream,cEncrypt));
objectOutputStream.flush();
ObjectInputStream objectInputStream = new ObjectInputStream(new CipherInputStream(socket.getInputStream,cDecrypt));
然後程序停止。代碼在套接字的兩側是相同的。如果不使用加密流,程序會正常傳輸數據。
任何幫助非常感謝,謝謝!
如果我使用CTR模式,我必須爲兩個終端使用公共IV嗎?或者是由Cipher obj的初始化處理? – 2011-04-26 00:10:36
感謝您的提示,它現在正在工作! 雖然,我用「AES/CFB8/NoPadding」 – 2011-04-26 03:30:46