Java-to-php encryption and decryption: encrypts encryptJsonUser () in the UserJsonUtil class and writes it into php encryption; decryptJsonUser () decrypts it into php decryption. Package & nbsp; com. test. moltest; import & nbsp; java. util. Co convert java to php for encryption and decryption
In the UserJsonUtil class
EncryptJsonUser () encryption, written as php encryption;
DecryptJsonUser () decryption, written as php decryption.
Package com. test. moltest;
Import java. util. Collection;
Import java. util. Iterator;
Import net. sf. json. JSONArray;
Import net. sf. json. JSONObject;
Import org. apache. commons. logging. Log;
Import org. apache. commons. logging. LogFactory;
Import com. capinfo. crypt. Md5;
/**
* Created by IntelliJ IDEA.
* User: bob_0703
* Date: 2008-10-18
* Time: 17:30:53
* To change this template use File | Settings | File Templates.
*/
Public class UserJsonUtil {
Private static final Log log = LogFactory. getLog ("UserJsonUtil. class ");
Public static boolean decryptJsonUser (String s ){
Boolean rs = false;
Try {
S = DESTools. decrypt ("testtest", s); // decrypt 1
JSONObject jobj = JSONObject. fromObject (s); // Convert to json
JSONArray names = jobj. names ();
String md5Str = (String) jobj. get ("md5"); // Obtain the encrypted MD5
Names. remove (names. size ()-1 );
StringBuffer buf = new StringBuffer ();
Iterator
It = names. iterator ();
While (it. hasNext ()){
String name = it. next ();
Buf. append (jobj. get (name ));
}
Jobj. remove ("md5 ");
Md5 md5 = new Md5 ("");
Md5.hmac _ Md5 (buf. toString (), "test ");
Byte B [] = md5.getDigest ();