-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
WebCrypto 的 PBKDF2 在迭代次数超过 100000 时会报错,建议补充说明或放开限制 #498
Copy link
Copy link
Open
Labels
Feedback Awaited 🕒 等待反馈Waiting for the feedback from issue creater and issue will be closed if duration is over one monthWaiting for the feedback from issue creater and issue will be closed if duration is over one monthRecommendation 🛠️ 建议RecommendationRecommendation
Metadata
Metadata
Assignees
Labels
Feedback Awaited 🕒 等待反馈Waiting for the feedback from issue creater and issue will be closed if duration is over one monthWaiting for the feedback from issue creater and issue will be closed if duration is over one monthRecommendation 🛠️ 建议RecommendationRecommendation
环境:
复现代码:
const password = new TextEncoder().encode("test123!@#");
const salt = crypto.getRandomValues(new Uint8Array(16));
crypto.subtle.importKey(
"raw",
password,
{ name: "PBKDF2" },
false,
["deriveBits"]
).then((keyMaterial) => {
return crypto.subtle.deriveBits(
{
name: "PBKDF2",
hash: "SHA-256",
salt,
iterations: 210000
},
keyMaterial,
256
);
}).then((bits) => {
console.log(bits);
}).catch((e) => {
console.error(e);
});
实际结果:
报错:
Pbkdf2 failed: iteration counts above 100000 are not supported (requested 210000)
预期结果:
补充说明:
这里使用的是标准 WebCrypto 接口,按常见安全建议会使用更高一些的迭代次数,但目前超过 100000 就直接失败,容易导致实际项目中登录/密码校验出现兼容性问题。