[英]Invalid salt version error in BCrypt.Net library - WinForms/C# application with MySQL DB
[英]jBCrypt 0.3 C# Port (BCrypt.net)
在研究了原始jBCrypt v0.1 C#端口中的錯誤之后: BCrypt.net ( 相關問題 )。 我決定將新的jBCrypt代碼與舊的C#端口進行比較,以查找差異和潛在問題,例如相關問題的錯誤。
這是我發現的:
// original java (jBCrypt v0.3):
private static int streamtoword(byte data[], int offp[]) {
int i;
int word = 0;
int off = offp[0];
for (i = 0; i < 4; i++) {
word = (word << 8) | (data[off] & 0xff);
off = (off + 1) % data.length;
}
offp[0] = off;
return word;
}
// port to C# :
private static uint StreamToWord(byte[] data, ref int offset)
{
uint word = 0;
for (int i = 0; i < 4; i++)
{
// note the difference with the omission of "& 0xff"
word = (word << 8) | data[offset];
offset = (offset + 1) % data.Length;
}
return word;
}
如果先驗是不正確的,以下將解決嗎?
private static uint StreamToWord(byte[] data, ref int[] offsetp)
{
uint word = 0;
int offset = offsetp[0];
for (int i = 0; i < 4; i++)
{
word = (word << 8) | (uint)(data[offset] & 0xff);
offset = (offset + 1) % data.Length;
}
offsetp[0] = offset;
return word;
}
在Java版本中, & 0xff
是必需的,因為在Java中,字節是帶符號的。 (有人認為這是一個錯誤。)
在C#中, 字節是無符號的 ,因此& 0xff
是不必要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.