예제 #1
0
파일: Digest.java 프로젝트: quzhaomei/admin
  /**
   * 对报文进行采用MD5进行hmac签名
   *
   * @param aValue - 字符�?
   * @param aKey - 密钥
   * @param encoding - 字符串编码方�?
   * @return - 签名结果,hex字符�?
   */
  public static String hmacSign(String aValue, String aKey, String encoding) {
    byte k_ipad[] = new byte[64];
    byte k_opad[] = new byte[64];
    byte keyb[];
    byte value[];
    try {
      keyb = aKey.getBytes(encoding);
      value = aValue.getBytes(encoding);
    } catch (UnsupportedEncodingException e) {
      keyb = aKey.getBytes();
      value = aValue.getBytes();
    }
    Arrays.fill(k_ipad, keyb.length, 64, (byte) 54);
    Arrays.fill(k_opad, keyb.length, 64, (byte) 92);
    for (int i = 0; i < keyb.length; i++) {
      k_ipad[i] = (byte) (keyb[i] ^ 0x36);
      k_opad[i] = (byte) (keyb[i] ^ 0x5c);
    }

    MessageDigest md = null;
    try {
      md = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
      return null;
    }
    md.update(k_ipad);
    md.update(value);
    byte dg[] = md.digest();
    md.reset();
    md.update(k_opad);
    md.update(dg, 0, 16);
    dg = md.digest();
    return ConvertUtils.toHex(dg);
  }
예제 #2
0
  public static void main(String[] args)
      throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    Company com = new Company();

    com.setName("");
    com.getName();

    // simple
    BeanUtils.setProperty(com, "name", "Jack");
    BeanUtils.getProperty(com, "name");

    // indexed
    BeanUtils.setProperty(com, "product[1]", "NOTES SERVER");
    BeanUtils.getProperty(com, "product[1]");

    // mapped
    HashMap am = new HashMap();
    am.put("1", "10010");
    am.put("2", "10010");
    BeanUtils.setProperty(com, "telephone", am);
    BeanUtils.getProperty(com, "telephone(2)");

    // combined
    BeanUtils.getProperty(com, "employee[1].name");

    // copyProperty
    Company com2 = new Company();
    BeanUtils.copyProperties(com2, com);

    // converter
    BeanUtils.setProperty(com, "date", new Date());

    BeanUtils.setProperty(com, "date", "2013-10-01");

    ConvertUtils.register(
        new Converter() {

          public <T> T convert(Class<T> type, Object value) {
            // TODO Auto-generated method stub
            return null;
          }
        },
        Date.class);

    // DynamicBean
    LazyDynaMap dynaBean = new LazyDynaMap();

    dynaBean.set("foo", "bar");
    dynaBean.set("customer", "title", "Rose");
    dynaBean.set("address", 0, "address1");
    System.out.println(dynaBean.get("address", 0));
    Map map = dynaBean.getMap();
    System.out.println(map.toString());

    // returnNull
    dynaBean.setReturnNull(true);

    // Restricted
    dynaBean.setRestricted(true);
  }
예제 #3
0
파일: Digest.java 프로젝트: quzhaomei/admin
 /**
  * 直接用MD5签名对数据签名,不需要密�?
  *
  * @param aValue
  * @return
  */
 public static String hmacSign(String aValue) {
   try {
     byte[] input = aValue.getBytes();
     MessageDigest md = MessageDigest.getInstance("MD5");
     return ConvertUtils.toHex(md.digest(input));
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
     return null;
   }
 }
예제 #4
0
파일: Digest.java 프로젝트: quzhaomei/admin
 /**
  * 直接用MD5签名对数据签名,不需要密�?
  *
  * @param aValue
  * @return
  */
 public static String signMD5(String aValue, String encoding) {
   try {
     byte[] input = aValue.getBytes(encoding);
     MessageDigest md = MessageDigest.getInstance("MD5");
     return ConvertUtils.toHex(md.digest(input));
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
     return null;
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
     return null;
   }
 }
예제 #5
0
파일: Digest.java 프로젝트: quzhaomei/admin
 /**
  * 对字符串进行签名
  *
  * @param aValue - 待签名字符串
  * @param alg - 签名算法名称(如SHA, MD5等)
  * @param encoding - 字符串编码方�?
  * @return - 签名结果,hex字符�?
  */
 public static String digest(String aValue, String alg, String encoding) {
   aValue = aValue.trim();
   byte value[];
   try {
     value = aValue.getBytes(encoding);
   } catch (UnsupportedEncodingException e) {
     value = aValue.getBytes();
   }
   MessageDigest md = null;
   try {
     md = MessageDigest.getInstance(alg);
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
     return null;
   }
   return ConvertUtils.toHex(md.digest(value));
 }
예제 #6
0
파일: Digest.java 프로젝트: quzhaomei/admin
 /**
  * tao.wu 2012-09-06 直接用MD5签名对数据签名,不需要密�?使用指定编码)
  *
  * @param aValue
  * @return
  */
 public static String hmacSignWithCharset(String aValue, String charset) {
   try {
     byte[] input = null;
     if (StringUtils.isBlank(charset)) {
       input = aValue.getBytes();
     } else {
       input = aValue.getBytes(charset);
     }
     MessageDigest md = MessageDigest.getInstance("MD5");
     return ConvertUtils.toHex(md.digest(input));
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
     return null;
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
     return null;
   }
 }