Java (Android) Decrypting msg with IV attached

為{幸葍}努か 提交于 2019-12-03 23:06:20
Robert

When using a block cipher with padding the encrypted text is always larger that the decrypted text. But you only copy as many bytes as the decrypted text has into the message to be sent. Therefore your encrypted message is incomplete.

byte[] encryped = cipher.doFinal(plainText.getBytes("UTF-8"));
byte[] data = new byte[iV.getIV().length + encrypted.length];
System.arraycopy(iV.getIV(), 0, data, 0, iV.getIV().length);
System.arraycopy(encrypted, 0, data, iV.getIV().length, encrypted.length);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!