AES,Java,Javascript之间的互操作性 [英] AES Interoperability between PHP, Java, Javascript

查看:113
本文介绍了AES,Java,Javascript之间的互操作性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发需要加密的HTTP API。我已经尝试使用AES来获得Java,PHP和Javascript之间的兼容性,但是到目前为止,我已经设法获得Java,PHP,然后Java,JavaScript,但不能同时支持PHP和Javascript。有人有任何经验可以实现这些语言之间的互操作性吗?



任何建议都将不胜感激。 / p>

谢谢

解决方案

要让AES在不同的系统上工作,必须确保所有系统上的一切是一样的。这意味着不依赖于任何系统默认值 - 系统之间的默认值可能不同。您需要明确指定所有内容。




  • 指定模式;使用CBC或CTR。

  • 指定IV。您可以将其添加到cyphertext。

  • 指定填充;对于AES使用PKCS7。

  • 如果您的密钥是文本字符串,则指定用于将其转换为字节的字符编码。

  • 如果您的明文是一个文本字符串然后指定用于将其转换为字节的字符编码。


I'm developing a HTTP API that requires encryption. I have tried to use AES to get compatibility between Java, PHP and Javascript, but so far I have managed to get Java<->PHP and then Java<->Javascript, but not both PHP and Javascript at the same time.

Has anyone had any experience with achieving interoperability between these languages and more?

Any advice would be much appreciated.

Thanks

解决方案

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,Java,Javascript之间的互操作性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆