SSLEngine unwrap() javax.crypto.BadPaddingException: bad record MAC

﹥>﹥吖頭↗ 提交于 2019-12-02 07:28:40

You're doing this wrong. When you need to get data you should:

  1. Get from your app receiver buffer.
  2. If that's empty, try unwrap().
  3. If that gives you a buffer underflow, read the channel.

Similarly when you need to put data, you should:

  1. Put to your app send buffer.
  2. If that fills, wrap().
  3. Write if that gives you a buffer overflow.

Or do all that when you need to flush.

Your primary interface should be with the engine, and only with the channel as a result of what the engine tells you about buffer underflows and overflows.

Similarly you must let the engine dictate the handshake (NEED_WRAP/NEED_UNWRAP) rather than try to dictate to it.

The SSLEngine is a very difficult thing to get right. Many have tried: few have succeeded. For one working success, that is the basis for a commercial product, see the SSLEngineManager class in the source code for my book Fundamental Networking in Java, Springer 2006, here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!