1 回答
TA贡献1744条经验 获得超4个赞
您的实现在逻辑上是正确的,但是有一些小问题,所有这些都与算法实现无关:
第一的
decodedBuffer.copy(salt, 13, 0, saltLength);
应该
// copy data from "decodedBuffer" buffer to "salt" buffer,
// from position 13, up to position 13 + saltLength of "decodedBuffer"
// to position 0 of "salt" buffer
decodedBuffer.copy(salt, 0, 13, 13 + saltLength);
只是因为它可以满足您的要求(从源数组中的位置13提取盐),而您的当前版本却做了完全不同的事情。我想您会弄混此功能的签名。
第二
let subkeyLength = hashedPassword.length - 13 - saltLength;
您已经在使用缓冲区,但是使用的长度hashedPassword是base-64字符串。这是不正确的(因为base-64字符串的长度和它表示的字节数组的长度不同),应该为:
let subkeyLength = decodedBuffer.length - 13 - saltLength;
第三
decodedBuffer.copy(expectedSubkey, 0, 13 + saltLength, expectedSubkey.length);
与第一个相同的故事应该是:
decodedBuffer.copy(expectedSubkey, 0, 13 + saltLength, 13 + saltLength + expectedSubkey.length);
进行此更改后,它将按预期工作。
- 1 回答
- 0 关注
- 180 浏览
添加回答
举报