0

嗨,我想复制在 asp.net 身份中完成的密码散列,这样,由 asp.net 身份散列的密码的结果值和由 Chilkat 散列的密码是相同的。这甚至可能吗?

在 C# asp.net 中,我们使用为我们执行 pbkdf2 的 Rfc2898DeriveBytes。我怎样才能在奇尔卡特做同样的事情?

    private const int PBKDF2IterCount = 1000; // default for Rfc2898DeriveBytes
    private const int PBKDF2SubkeyLength = 256 / 8; // 256 bits
    private const int SaltSize = 128 / 8; // 128 bits

    //[ComVisible(true)]
    public string HashPassword(string password)
    {
        if (password == null)
        {
            throw new ArgumentNullException("password cannot be null");
        }

        // Produce a version 0 (see comment above) text hash.
        byte[] salt;
        byte[] subkey;
        using (var deriveBytes = new Rfc2898DeriveBytes(password, SaltSize, PBKDF2IterCount))
        {
            salt = deriveBytes.Salt;
            subkey = deriveBytes.GetBytes(PBKDF2SubkeyLength);
        }

        var outputBytes = new byte[1 + SaltSize + PBKDF2SubkeyLength];
        Buffer.BlockCopy(salt, 0, outputBytes, 1, SaltSize);
        Buffer.BlockCopy(subkey, 0, outputBytes, 1 + SaltSize, PBKDF2SubkeyLength);
        return Convert.ToBase64String(outputBytes);
    }

目前,我在 Chilkat 使用的参数是:

 Function EncryptChilkat(sPassword As String) As String

Dim crypt As New ChilkatCrypt2

Dim success As Long

success = crypt.UnlockComponent("ACHIEV.CR1082018_dCrRA3zr4e1M ")

If (success <> 1) Then
    Debug.Print crypt.LastErrorText
    Exit Function
End If

Dim hexKey As String

Dim pw As String
pw = "pwd"
Dim pwCharset As String
pwCharset = "base64"

'  Hash algorithms may be: sha1, md2, md5, etc.
Dim hashAlg As String
hashAlg = "HMCSHA1"

'  The salt should be 8 bytes:
Dim saltHex As String
saltHex = "78578E5A5D63CB06"

Dim iterationCount As Long
iterationCount = 1000

'  Derive a 128-bit key from the password.
Dim outputBitLen As Long
outputBitLen = 128

'  The derived key is returned as a hex or base64 encoded string.
'  (Note: The salt argument must be a string that also uses
'  the same encoding.)
Dim enc As String
enc = "base64"

hexKey = crypt.Pbkdf2(pw, pwCharset, hashAlg, saltHex, iterationCount, outputBitLen, enc)

EncryptChilkat = hexKey
End Function
4

1 回答 1

0

检查双方密码和盐的二进制值。还要检查尾随的空值、回车符和换行符。

此外,您可以查看哪一种算法行为不端——我在我的 github 存储库中有一份 Jither 的 .NET PBKDF2 实现副本,包括测试向量,对于您的 Chillkat,您可以从我的 LibreOffice Calc 表中创建您需要的 PBKDF2测试向量

通过这两个实现运行这些;哪个失败就是错误的。如果两者都成功......那么你没有给出相同的参数。

于 2018-01-27T07:26:58.297 回答