Beispiel #1
0
  public static void main(String[] args) throws Exception {
    /*
     * 此处使用AES-128-ECB加密模式,key需要为16位。
     */
    String key = "1234567890123456";
    // 需要加密的字串
    String data = "数据";
    System.out.println(data);
    // 加密
    String enString = AesEncryption.encrypt(data, key);
    System.out.println("加密后的字串是:" + enString);

    // 解密
    String deString = AesEncryption.decrypt(enString, key);
    System.out.println("解密后的字串是:" + deString);
  }
Beispiel #2
0
 /**
  * https get方式调用服务
  *
  * @author 黄永丰
  * @createtime 2015年7月21日
  * @param serviceName 服务名称
  * @param method 接口方法名称
  * @param data 传入数据
  * @return 调用完接口数据
  */
 public static String httpSSLGet(String serviceName, String interfaceName, String data) {
   String result = "";
   try {
     String appKey = ""; // 授权给应用的key
     String appSecret = ""; // 授权给应用的密钥
     String openApiUrl = "";
     String format = "json";
     String aesdata = AesEncryption.encrypt(data, appSecret); // 采用AES加密数据
     String version = "1.0"; // 版本
     String timestamp = String.valueOf(System.currentTimeMillis());
     String session = "";
     // 签名(用md5加密 appKey + interfaceName + format + aesdata + version + timestamp + session +
     // appKey)
     String sign =
         MD5Util.getMD5(
             appKey
                 + interfaceName
                 + format
                 + aesdata
                 + version
                 + timestamp
                 + session
                 + appSecret);
     String param =
         "appKey="
             + appKey
             + "&interfaceName="
             + interfaceName
             + "&format="
             + format
             + "&data="
             + aesdata
             + "&version="
             + version
             + "&timestamp="
             + timestamp
             + "&session="
             + session
             + "&sign="
             + sign;
     openApiUrl = openApiUrl + "?" + param;
     result = HttpsUtil.sslGet(openApiUrl, "UTF-8");
   } catch (Exception e) {
     result = e.getMessage();
   }
   return result;
 }