Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NacosRefreshHistory uses BigInteger's toString(16) method to calculate md5. #3853

Open
photowey opened this issue Sep 19, 2024 · 0 comments
Open
Assignees
Labels
area/nacos spring cloud alibaba nacos kind/question

Comments

@photowey
Copy link

NacosRefreshHistory 直接采用 BigInteger 的 toString(16) 方法来计算 MD5,是否有计算结果长度不足32位数的风险?
NacosRefreshHistory uses BigInteger's toString(16) method to calculate md5. Is there a risk that the calculated result will be less than 32 digits long?

Which Component
Nacos 配置中心
Nacos(spring-cloud-starter-alibaba-nacos-config)
版本: 2023.x
version: 2023.x

Describe what problem you have encountered
直接采用 BigInteger#toString(16) 计算 md5
NacosRefreshHistory uses BigInteger's toString(16) method to calculate md5.

// com.alibaba.cloud.nacos.refresh.NacosRefreshHistory#md5
private String md5(String data) {
    if (StringUtils.isEmpty(data)) {
        return null;
    }
    if (null == md) {
        try {
            md = MessageDigest.getInstance("MD5");
        }
        catch (NoSuchAlgorithmException ignored) {
            return "unable to get md5";
        }
    }

   // toString(16) ?
    return new BigInteger(1, md.digest(data.getBytes(StandardCharsets.UTF_8)))
        .toString(16);
}

Describe what information you have read
直接阅读源码发现的。
I have read the source code of Nacos(spring-cloud-starter-alibaba-nacos-config).

@yuluo-yx yuluo-yx added kind/question area/nacos spring cloud alibaba nacos labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/nacos spring cloud alibaba nacos kind/question
Projects
None yet
Development

No branches or pull requests

3 participants