How to decrypt a file in javascript which is encrypted by JAVA with AES

不打扰是莪最后的温柔 提交于 2019-12-03 21:54:24

Your key is wrong, Java (incorrectly) uses the ASCII representation of the key:

String key = "1234567890123456789012345678901d";
...
SecretKeySpec newKey = new SecretKeySpec(key.getBytes("UTF-8"), "AES");

which results in a 32 byte key for AES-256. But your JavaScript uses the Hex decoding of the key:

var key =  CryptoJS.enc.Hex.parse("1234567890123456789012345678901d");

which results in a 16 byte key for AES-128.

With wrong keys you will obviously not get the right results.

So you'd either have to encode your key as you did your IV in Java or use a hex decoder (not present in Java by default) or you should "fix" your JavaScript to do the same as in Java and use the ASCII encoding of the key string.

Keys, in general, should not be strings.

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