签名问题

签名验签不通过检测

1. 检查字段拼接方式是否正确

2. 字符串转二进制数组时是否正确(重点)

通常我们进行二进制转换是指调用String的getByte()无参数方法,该方法在转换时默认获取当前系统的字符格式:

if (defaultCharset == null) {
            synchronized (Charset.class) {
                String csn = AccessController.doPrivileged(
                    new GetPropertyAction("file.encoding"));
                Charset cs = lookup(csn);
                if (cs != null)
                    defaultCharset = cs;
                else
                    defaultCharset = forName("UTF-8");
            }
        }

如果获取字符编码异常,默认使用iso-8859-1形式:

      try {
            // use charset name encode() variant which provides caching.
            return encode(csn, ca, off, len);
        } catch (UnsupportedEncodingException x) {
            warnUnsupportedCharset(csn);
        }
        try {
            return encode("ISO-8859-1", ca, off, len);
        } catch (UnsupportedEncodingException x) 
        .....

因此在进行签名过程中需要将字符串转换成二进制数组时,都要使用getByte(charSetName)的方式指定编码集

3. 请求方式是否正确

使用httppost请求时,无法直接通过指定header的方式设置ContentType,需在entry体中设置ContentType

	HttpPost post = new HttpPost(url);
		StringEntity entity = new StringEntity(json,"UTF-8");
    entity.setContentType("application/json");
		post.setEntity(entity);

转载于:https://my.oschina.net/dreamForMe/blog/1796770

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值