Re: [問題] AES加解密
※ 引述《yorjing (問題兒童)》之銘言:
: a.java
: http://dpaste.com/57980/
: b.java
: http://dpaste.com/57981/
: client side(b.java) exception
: http://dpaste.com/57982/
: 錯誤在b.java的
: aesKey=SecretKeyFactory.getInstance("AES").generateSecret(s);
: 可以請問大大這樣的錯誤要怎麼修正嗎?
: 小弟看api寫的
: 不知道錯在哪裡?
1. To solve NoSuchAlgorithmException, try this:
SecretKeySpec s=new SecretKeySpec(buffer,"AES");
Cipher aesDeCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
aesDeCipher.init(Cipher.DECRYPT_MODE, ss);
No Factory needed again in this case.
2. 就算你改好了這個問題後,我猜結果還是會跑出別的 Exception
因為你沒有好好學過 stream input/output ...
InputStream.read(buffer) 是沒法保證一次就能讀完 buffer.length 的東西的
而且你還定了 buffer length = 1024,你也沒法保證 key encodebyte 的長度
一定是 1024
解決方法: 先重新去學一次 input/output stream.
--
《為了要得到真相,就要向原 PO 伸圖》
那就是伸圖魔人的沒圖沒真相原則,那時我們堅信那就是逼逼死的真實
靠么,圖咧?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.218.38.49
※ 編輯: superlubu 來自: 203.218.38.49 (06/22 07:46)
推
06/22 07:58, , 1F
06/22 07:58, 1F
→
06/22 08:18, , 2F
06/22 08:18, 2F
推
06/22 09:23, , 3F
06/22 09:23, 3F
→
06/22 09:25, , 4F
06/22 09:25, 4F
推
06/22 09:27, , 5F
06/22 09:27, 5F
推
06/22 09:32, , 6F
06/22 09:32, 6F
推
06/22 10:07, , 7F
06/22 10:07, 7F
討論串 (同標題文章)