Loading...

    修改用户密码

    功能说明

    修改用户密码。只能使用签名 2.0

    默认接口请求频率限制:20次/秒。

    实现方法

    REST URL

    POST /api/rest/external/v1/user/password/change?enterpriseId=XXX

    请求参数说明

    参数

    参数类型

    参数位置

    必须

    默认值

    说明

    初始平台

    enterpriseId

    String

    Query

    企业ID

    5.2-20260626

    公有云不存在

    phone

    String


    Body

    账号

    5.2-20260626

    公有云不存在

    password

    String

    Body

    SM4加密后的hex密文

    5.2-20260626

    公有云不存在

    示例代码

    请求示例:

    {
    "phone": "account001",
    "password": "SM4加密后的hex密文"
    }

    加密算法细节:

    项目


    算法

    SM4/CBC/PKCS7Padding

    Provider

    Bouncy Castle

    明文编码

    UTF-8

    密文格式

    hex 小写字符串

    key 来源

    clientSecret UTF-8 字节的前 16 字节;不足 16 字节右侧补 0x00

    IV 来源

    先按上述规则得到 16 字节 key,再对这 16 字节升序排序,排序后的字节作为 IV

    Java 加密方法

    Gradle 依赖:

    implementation 'org.bouncycastle:bcprov-jdk15on:1.57'

    可直接复制的工具方法:

    import org.bouncycastle.jce.provider.BouncyCastleProvider;
    import org.bouncycastle.util.encoders.Hex;

    import javax.crypto.Cipher;
    import javax.crypto.spec.IvParameterSpec;
    import javax.crypto.spec.SecretKeySpec;
    import java.nio.charset.StandardCharsets;
    import java.security.Security;
    import java.util.Arrays;

    public final class SdkPasswordEncryptor {
    private static final String ALGORITHM = "SM4/CBC/PKCS7Padding";

    static {
    if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
    Security.addProvider(new BouncyCastleProvider());
    }
    }

    private SdkPasswordEncryptor() {
    }

    /**
    * 输入原始密码和 UAA clientSecret,返回可传给 password 字段的 SM4 hex 密文。
    */
    public static String encryptPassword(String rawPassword, String clientSecret) throws Exception {
    if (rawPassword == null || rawPassword.trim().isEmpty()) {
    throw new IllegalArgumentException("rawPassword cannot be empty");
    }
    if (clientSecret == null || clientSecret.trim().isEmpty()) {
    throw new IllegalArgumentException("clientSecret cannot be empty");
    }

    Cipher cipher = Cipher.getInstance(ALGORITHM, BouncyCastleProvider.PROVIDER_NAME);
    byte[] keyBytes = normalizeKey(clientSecret.getBytes(StandardCharsets.UTF_8));
    SecretKeySpec secretKey = new SecretKeySpec(keyBytes, ALGORITHM);

    byte[] ivBytes = Arrays.copyOf(keyBytes, keyBytes.length);
    Arrays.sort(ivBytes);

    cipher.init(Cipher.ENCRYPT_MODE, secretKey, new IvParameterSpec(ivBytes));
    byte[] plainBytes = rawPassword.getBytes(StandardCharsets.UTF_8);
    byte[] encryptedBytes = cipher.doFinal(plainBytes);
    return Hex.toHexString(encryptedBytes);
    }

    private static byte[] normalizeKey(byte[] source) {
    byte[] result = new byte[16];
    System.arraycopy(source, 0, result, 0, Math.min(source.length, 16));
    return result;
    }
    }

    调用示例:

    String encryptedPassword = SdkPasswordEncryptor.encryptPassword("Sdk@2026Pwd!", clientSecret);


    返回结果示例:

    成功时返回200,失败时返回小鱼RESTAPI错误码

    意见反馈