早期接口加密处理方式

客户端

String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
//生成摘要,
// MD5:时间戳+密钥+用户信息
String md5Info = time + ConstantValue.AGENTER_PASSWORD + body;
String md5=DigestUtils.md5Hex(md5Info);
//  对用户信息进行加密。
return new DES().authcode(elementsInfo,"DECODE",ConstantValue.DES_PASSWORD);

服务器端解密,首先解密信息,然后验签,验签正确才获取信息。

DES des = new DES();
String bodyInfo = des.authcode(result.getBody().getDesInfo(), "ENCODE", ConstantValue.DES_PASSWORD);
String md5Info = result.getHeader().getTimestamp().getValue() + Constant.APP_PASSWORD + bodyInfo;
String md5Hex = DigestUtils.md5Hex(md5Info);
if (md5Hex.equals(result.getHeader().getDigest().getValue())) {
    result.getBody().setBodyResult(bodyInfo);
    return result;
}

你可能感兴趣的:(早期接口加密处理方式)