Skip to main content

华住商旅敏感信息加密对接

敏感信息数据(如姓名、手机号、身份证号等)额外采用AES加密,采用AES算法进行数据加密传输,提供机密性、完整性和真实性保障。加密数据需包含16字节随机IV(初始向量),所有加密操作必须配合TLS 1.2协议使用,实现端到端双重保护。请确保对接系统正确实现AES加解密逻辑,严格管理密钥安全。具体加密示例详见如下文档内容。


(华住商旅敏感信息加密对接前,请先联系商务开通配置)

第一、敏感信息数据范围

  1. 姓名(注意接口中字段姓名,姓,名都会加密)
  2. 手机号
  3. 邮箱
  4. 证件类型
  5. 证件号码

第二、涉及接口范围(包含入参和出参)

  1. 下单前验证是否可定指定房型接口(/hotel/checkAvailability)
  2. 下单接口(order/add)
  3. 查询接口(order/query)
  4. 根据下单号查询订单(order/queryByRequestNo)
  5. 查询取消/提前离店申请单详情(order/discrepantReservationDetail)
  6. 企业查询房单信息(bill/searchBillListByCompany)
  7. 回调接口
    1. 预订单信息推送企业(回调接口)
    2. 企业接待信息推送企业(回调接口)
    3. 个人接待信息推送企业(回调接口)
  8. 员工信息同步接口
    1. 新增员工(userInfo/addUser)
    2. 员工信息修改(userInfo/modifyUser)
    3. 员工信息删除(userInfo/deleteUser)
  9. 员工信息查询(userInfo/queryUser)
  10. 企业员工认证接口
    1. 企业员工认证会员(/external/registerComplete)
    2. 会员等级查询(/member/getMemberInfo)
    3. 会员信息补全(/external/member/updatePersonInfo)

第三、加解密信息对接代码

package com.xxx.xxx.common.utils;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;

public class AESUtil {

private static final String ALGORITHM = "AES";
private static final String CBC_MODE = "AES/CBC/PKCS5Padding";

/**
* AES CBC 加密
*
* @param content 需要加密的内容
* @param password 密钥(16位)
* @return 加密后的内容(Base64 编码)
*/
public static String encrypt(String content, String password) {
try {
Cipher cipher = Cipher.getInstance(CBC_MODE);
SecretKeySpec keySpec = new SecretKeySpec(password.getBytes(), ALGORITHM);
IvParameterSpec iv = new IvParameterSpec(password.substring(0, 16).getBytes());
cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv);

byte[] encrypted = cipher.doFinal(content.getBytes());
return Base64.getEncoder().encodeToString(encrypted);
} catch (Exception e) {
throw new RuntimeException("AES encrypt error", e);
}
}

/**
* AES CBC 解密
*
* @param content 需要解密的内容(Base64 编码)
* @param password 密钥(16位)
* @return 解密后的内容
*/
public static String decrypt(String content, String password) {
try {
Cipher cipher = Cipher.getInstance(CBC_MODE);
SecretKeySpec keySpec = new SecretKeySpec(password.getBytes(), ALGORITHM);
IvParameterSpec iv = new IvParameterSpec(password.substring(0, 16).getBytes());
cipher.init(Cipher.DECRYPT_MODE, keySpec, iv);

byte[] decoded = Base64.getDecoder().decode(content);
byte[] decrypted = cipher.doFinal(decoded);
return new String(decrypted);
} catch (Exception e) {
throw new RuntimeException("AES decrypt error", e);
}
}

// 测试示例
public static void main(String[] args) {
String content = "Hello, World!";
String password = "FA145089E1223611"; // 16字节

String encrypted = encrypt(content, password);
System.out.println("Encrypted: " + encrypted);

String encrypted1 = encrypt("陈", password);
System.out.println("Encrypted1: " + encrypted1);
String encrypted2 = encrypt("龙", password);
System.out.println("Encrypted2: " + encrypted2);
String encrypted3 = encrypt("11111111111", password);
System.out.println("Encrypted3: " + encrypted3);



String decrypted = decrypt(encrypted, password);
System.out.println("Decrypted: " + decrypted);
}
}

参数名AES:AES密钥