jBCrypt 0.3 C#端口(BCrypt.net) [英] jBCrypt 0.3 C# Port (BCrypt.net)

查看:373
本文介绍了jBCrypt 0.3 C#端口(BCrypt.net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找到一个bug在原有V0.1 jBCrypt C#端口后:的 BCrypt.net (的相关问题)。我决定来比较旧的C#端口寻找差异和潜在的问题,如有关问题的错误新jBCrypt代码



下面是我发现:

  //原始的Java(jBCrypt V0.3):
私有静态诠释streamtoword(字节数据[],INT石油换食品计划[]){
INT I;
INT字= 0;
INT关闭石油换食品计划= [0];

表示(I = 0; I&下; 4;我++){
字=(词下;&下; 8)| (数据[关闭]放大器; 0xFF的);
=关(关+ 1)%data.length;
}

石油换食品计划[0] =关闭;
反馈字;
}


//端口C#:
私有静态UINT StreamToWord(字节[]数据,楼盘INT偏移)
{

UINT字= 0;

的for(int i = 0;我4;;我++)
{
//注意与遗漏的区别&放大器; 0xFF的
字=(词下;&下; 8)|数据[偏移]
偏移=(偏移+ 1)%data.Length;
}

返回字;
}

如果事先不正确,将下面的解决?



 私有静态UINT StreamToWord(字节[]数据,文献INT [] offsetp)
{

UINT字= 0;
INT偏移= offsetp [0];
的for(int i = 0;我4;;我++)
{
字=(字LT;< 8)| (UINT)(数据[偏移]放大器; 0xFF的);
偏移=(偏移+ 1)%data.Length;
}

offsetp [0] =偏移;

返回字;
}


解决方案

&安培; 0xFF的在Java版本必需的,因为在Java中,字节签名。 (有些人认为这是一个错误。)



在C#中,的字节是无符号,因此&安培; 0xFF的是不必要的。


After looking into a bug in the original jBCrypt v0.1 C# port: BCrypt.net (Related Question). I decided to compare the new jBCrypt code against the old C# port to look for discrepancies and potential issues like the related question's bug.

Here is what I've found:

// 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;
}

if the prior is incorrect would the following fix it?

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;
}

解决方案

The & 0xff is required in the Java version because in Java, bytes are signed. (Some argue that this is a bug.)

In C#, bytes are unsigned, so the & 0xff is unnecessary.

这篇关于jBCrypt 0.3 C#端口(BCrypt.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆