サーバーとクライアントのソケットプログラムがあり、サーバーは暗号化されたメッセージをクライアントに送信します。つまり、サーバー側のコードです。
cipher2 = Cipher.getInstance("AES");
secretKeySpec = new SecretKeySpec(decryptedText, "AES");
cipher2.init(Cipher.ENCRYPT_MODE, secretKeySpec);
feedback = "Your answer is wrong".getBytes();
cipher2.doFinal(feedback);
dos.writeInt(feedback.length);
dos.write(feedback);
クライアント側のコード:
int result_len = 0;
result_len = din.readInt();
byte[] result_Bytes = new byte[result_len];
din.readFully(result_Bytes);
cipher2 = Cipher.getInstance("AES");
cipher2.init(Cipher.DECRYPT_MODE, aesKey);
byte[] encrypt = cipher2.doFinal(result_Bytes);
例外スローbyte[] encrypt = cipher2.doFinal(result_Bytes);
javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:750)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:313)
at javax.crypto.Cipher.doFinal(Cipher.java:2086)
何が問題ですか?