I've a project in vb.net/Jquery. Where I use a encryption function to validate connexion to my Intranet.
Public Shared Function ValidatePassword(passwordToTest As String, passwordParam As paramPassword) As Boolean
Dim hash() As Byte = passwordParam.hashByteArray
Dim testHash() As Byte = PBKDF2(passwordToTest, passwordParam.saltByteArray, passwordParam.iteration, passwordParam.hashByteArraySize)
Return SlowEquals(hash, testHash)
End Function
Private Shared Function SlowEquals(a() As Byte, b() As Byte) As Boolean
Dim diff As UInteger = CUInt(a.Length) Xor CUInt(b.Length)
For i As Integer = 0 To Math.Min(a.Length, b.Length) - 1
diff = CUInt(a(i) Xor b(i)) Or diff
Next
Return diff = 0
End Function
Private Shared Function PBKDF2(password As String, salt() As Byte, iterations As Integer, outputBytes As Integer) As Byte()
Dim PBKDF2_hasher As Rfc2898DeriveBytes = New Rfc2898DeriveBytes(password, salt)
PBKDF2_hasher.IterationCount = iterations
Return PBKDF2_hasher.GetBytes(outputBytes)
End Function
Now If I'm offline, I want to check the connexion from indexdb. Then I try to simulated this function bit i failed again and again. I see this but Need node.js. I failed to adapted and I prefer don't put node.js just for that I see this other one here, but it's very long and I failed to put result in variable and worst the result is different from my hash... I see cryptojs from google but don't understand how to use it. When I download it i've 2 folders : components/rollups??
Someone can help me to find a simple way to use a crypto library and how to use it?