Convert java to php encryption and encryption

Source: Internet
Author: User
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 ();
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.