AES Interoperability between PHP, Java, Javascript

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 18:13:45

To get AES to work across different systems, you have to make sure that everything is the same on all systems. That means not relying on system defaults for anything - defaults can differ between systems. You need to explicitly specify everything.

  • specify the mode; use CBC or CTR.
  • specify the IV. You can prepend it to the cyphertext.
  • specify the padding; for AES use PKCS7.
  • if your key is a text string then specify the character encoding used to convert it to bytes.
  • if your plaintext is a text string then specify the character encoding used to convert it to bytes.

AES is a standard (defined here). No matter which programming language you use, the result has to be the same.

Check some test vectors either from the official definition or - if you've already implemented a block mode of operation - from here.

If your implementation has different result, it might work, but it won't be AES...

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