简体   繁体   English

Java中的加密和PHP中的解密

[英]Encryption in Java and decryption in PHP

I have to decrypt string in PHP, which is being generated from Java class. 我必须在PHP中解密字符串,这是从Java类生成的。 And I am not able to understand what exactly is being done in that class. 我无法理解该课程究竟在做什么。 Java class used for encryption-decryption 用于加密 - 解密的Java类

Can someone suggest me the equivalent code or process to decrypt the encrypted string. 有人可以建议我使用等效的代码或进程来解密加密的字符串。

that Java class seems to do a DES encryption. Java类似乎在进行DES加密。

In PHP you can do: 在PHP中,您可以:

$result=mcrypt_decrypt ( "MCRYPT_DES" , $key , $data , $mode);

The $key and $mode variables are information you should know, $data is the input encrypted string. $ key和$ mode变量是你应该知道的信息,$ data是输入的加密字符串。 You may want to try MCRYPT_3DES if the other one doesn't work. 如果另一个不起作用,您可能想尝试MCRYPT_3DES。

Well, if even you don't seem to know, which encryption algorithm is used, it's hard for us to help you. 好吧,即使您似乎不知道使用了哪种加密算法,我们也很难帮助您。 I'm not familiar with the code and the classes which are used there but it seems that DES is used (no shit) in a weird combination with Base64. 我不熟悉那里使用的代码和类,但似乎在与Base64的奇怪组合中使用了DES(没有糟糕)。 Search for DES decryption with PHP, also PHP has functions for handling Base64-String. 使用PHP搜索DES解密,PHP也具有处理Base64-String的功能。

You can also search for what SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec); 您还可以搜索SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec); does. 确实。

The code you linked generates an encryption key using a salt, passphrase and the number of md5 iterations. 您链接的代码使用salt,passphrase和md5迭代次数生成加密密钥。

With the encryption key you can encrypt / decrypt. 使用加密密钥,您可以加密/解密。

A couple of years ago I implemented a php version of the used algorithm PBEWithMD5AndDES: https://github.com/KevinBusse/PBEWithMD5AndDES 几年前我实现了使用的算法PBEWithMD5AndDES的php版本: https//github.com/KevinBusse/PBEWithMD5AndDES

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM