我们在 实时发放数据上报
, 实时发放回调通知
两个场景中对敏感数据进行了 AES加密
, 你可以使用下面的方式进行加密解密:
1. 加解密说明
- 加解密方式为
AES/CBC/PKCS5Padding
- 加解密密钥为
AccessKeySecret
- 加密生成的字符格式为
UTF-8
编码的Base64
字符串 - 加密向量值
iv
为:0000000000000000 (16个阿拉伯数字0)
请注意:
- 加密完成后需要一次
UrlEncode
- 解密数据前需要一次
UrlDecode
(通知回调包体解密无需此步骤)
2. 示例代码
2.1 加密代码示例
final String IV_STRING = "0000000000000000";
String sourceString = ""; // 待加密字符串
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec skeySpec = new SecretKeySpec(AccessKeySecret.getBytes("UTF-8"), "AES");
IvParameterSpec iv = new IvParameterSpec(IV_STRING.getBytes("UTF-8"));
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
byte[] encrypted = Base64.encode(cipher.doFinal(sourceString.getBytes("UTF-8")));
// 加密完成后进行UrlEncode
return URLEncoder.encode(encrypted)
2.2 解密代码示例
final String IV_STRING = "0000000000000000";
String sourceString = ""; // 解密密字符串
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec skeySpec = new SecretKeySpec(AccessKeySecret.getBytes("UTF-8"), "AES");
IvParameterSpec iv = new IvParameterSpec(IV_STRING.getBytes("UTF-8"));
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
// 解密前进行UrlDecode (通知包体解密无需此步骤)
String encrypted = URLDecoder.decode(sourceString);
byte[] bytes = cipher.doFinal(Base64.decode(encrypted));
return new String(bytes, "UTF-8");
3. 实时发放数据上报加密示例
业务参数JSON串
AccessKeySecret
18a9722d3bc84812830b2306b72e4605
加密结果
90BCnLDJ9czbEEusRowegeKj02I9RGGNOZnq7nmh3rXmD3EQVZm%2BIbC%2ByfY%2FQyuVoW4uLkwu%2FJssN0PVsk9goS1YjIhqdUsmbec6NDaB5mPwUbOQpEMpt1RFaDTvv0Nr9yfwRNmusn%2FveAhgq1MmFw%2BUQxOvK7FTaJV3OzR5UXZN4WRWfCGSfSDBQtZfAtlOd2WAy5TPCBsvXsTcs55XcuJ%2BmyI2Lf4QlrBG%2FvkyXIhhOebbiqsuapy7uV7gtBzN2%2BzARc2mseWc0mky9mJVNNe9BJcAdRaQC4NPPZVGkhMQOvqbqELUY0mX%2Fn%2FMOITc%2BT9wiux8ZPvM041JOmHKZmD2FQ6Q1AWF1NSTlPpJ08PmSyGh7Bk9fS3lWnnVcEBO0utGAqJHfb28nJJ%2Bit9ox8pelqGieS2vDA22kcfmdHAtZ%2FNakHbb1STU7pkTn5q3U2IPqVTJBp%2BAYwKrLpAbDvaMs7ZK71jWgtjUxnaNZDw%3D
4. 测试工具
请复制到浏览器打开