mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-10 23:47:29 +00:00
fix: 修复 PasswordUtil.checkPassword 中的时序攻击漏洞,使用 MessageDigest.isEqual()
This commit is contained in:
@@ -80,8 +80,10 @@ public class PasswordUtil {
|
||||
byte[] calculatedHash = md.digest(plainPassword.getBytes(StandardCharsets.UTF_8));
|
||||
String calculatedHashBase64 = Base64.getEncoder().encodeToString(calculatedHash);
|
||||
|
||||
// 比较计算出的哈希值和存储的哈希值
|
||||
return hashBase64.equals(calculatedHashBase64);
|
||||
// 比较计算出的哈希值和存储的哈希值(使用常量时间比较防止时序攻击)
|
||||
return MessageDigest.isEqual(
|
||||
hashBase64.getBytes(StandardCharsets.UTF_8),
|
||||
calculatedHashBase64.getBytes(StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
// 如果发生异常(例如格式不正确),返回false
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user