Any Equivalent for mcrypt (in PHP) to use in Java?

跟風遠走 提交于 2019-12-21 02:34:22

问题


Can any one tell about any library that can be used in java, which gives the same result if operation was done in PHP using the mcrypt library.

i want to actually encrypt a string in Java using AES, and decrypt it in PHP. Will the Java Cipher yield a encryption decryptable by mcrypt in PHP?

edit:

Found some resin-3.1 library in Web. Can it be?


回答1:


Encryption algorithms are programming language independent.

As long as the:

  • Cipher (eg: AES, DES, Blowfish, etc.),
  • Mode of operation (eg: CBC, CTR, OFB, etc.) ,
  • Key,
  • IV and
  • Padding (mcrypt uses zero-padding)

are all the same, you'll be able to encrypt and decrypt data regardless of the programming language used (assuming the implementations are correct).

Just remember that Java's Cipher works on byte arrays, so if you are encrypting a string, you'll need to use String.getBytes() to get a byte array.



来源:https://stackoverflow.com/questions/7821678/any-equivalent-for-mcrypt-in-php-to-use-in-java

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