TestCookieDecode.java Source code

Java tutorial

Introduction

Here is the source code for TestCookieDecode.java

Source

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

import com.greenline.guahao.biz.util.DESUtils;
import com.greenline.guahao.web.module.common.constants.EncodeKeyConstants;

/*
 * Project: guahao-portal-web-war
 * 
 * File Created at 2012-6-15
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */

/**
 * @Type TestCookieDecode
 * @Desc
 * @author weirui.shenwr
 * @date 2012-6-15
 * @Version V1.0
 */
public class TestCookieDecode {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        // // TODO Auto-generated method stub
        // DefaultCryptoBeanDefinition() blowfishCrypto = new
        // DefaultCryptoBeanDefinition();
        // blowfishCrypto.setAlgorithm("Blowfish");
        // blowfishCrypto.setTransformation("Blowfish/CBC/NoPadding");
        // blowfishCrypto.setKey(cryptoKey);
        // blowfishCrypto.setProvider("CryptixCrypto");
        //
        // java.security.Security.addProvider(new
        // cryptix.jce.provider.CryptixCrypto());
        // String key="^#16qweqv88cde729!@#$3450abfg^%";
        // SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(),
        // "Blowfish");
        // Cipher deCipher =
        // Cipher.getInstance("Blowfish/CBC/NoPadding","CryptixCrypto");
        // deCipher.init(Cipher.DECRYPT_MODE, secretKey);
        // byte[] ret= deCipher.doFinal(
        // Base64Util.decode("ihxD3imKsk724mCURZhHkD3QbIzWcXp3NbZBi72ilN9td+XSaN5nYUH1N7JwXKMj"));
        // System.out.println(new String(ret).substring(8).trim());

        HttpClient client = new HttpClient();
        client.getHostConfiguration().setHost("www.guahao.com", 80);
        PostMethod post = new PostMethod("/outSysGetUserCookieValue");
        NameValuePair name = new NameValuePair("signdata", "PjPQvzc6j1UOmThSb3IUkw==");
        NameValuePair pass = new NameValuePair("cookieValue",
                "{\"__uli__\":\"sDZXBw9ZZm/QM3lksxZ7mVjUFIbpup7//oPTueSeWY1XhNAQhIPSPiPFV5EqKMoO3qeJSLoBdt3LxwvuTUSW9g==\"}");
        post.setRequestBody(new NameValuePair[] { name, pass });
        client.executeMethod(post);
        System.out.println(post.getResponseBodyAsString());
        post.releaseConnection();

        String signdata = DESUtils.dCode("Py8o3huCfMcSJR4HBjDe0w==", EncodeKeyConstants.OUT_SYS_USER_KEY);
        System.out.println(signdata);

    }
}