Implementierung einer besseren Radom und rechenintensiveren Hash-Aart
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
Imports System.Security.Cryptography
|
||||
Imports Microsoft.VisualBasic
|
||||
|
||||
Imports Konscious.Security.Cryptography
|
||||
Public Class VERAG_VARIABLES
|
||||
Public Shared errornumb As Integer = 0
|
||||
Shared Function getiterationnumber() As Integer
|
||||
Return RandomInteger(Math.Pow(2, 2), Math.Pow(2, 8))
|
||||
End Function
|
||||
|
||||
Shared Sub initerrorcount()
|
||||
errornumb = 0
|
||||
End Sub
|
||||
@@ -15,20 +19,38 @@ Public Class VERAG_VARIABLES
|
||||
Shared Function getErrorcodeindez(Errorcode As String) As String
|
||||
Return VERAG_PROG_ALLGEMEIN.cCryptography3.Decrypt(Errorcode)
|
||||
End Function
|
||||
Public Shared Function GenerateSalt(ByVal nSalt As Integer) As String
|
||||
Public Shared Function GenerateSalt(ByVal nSalt As Integer) As Byte()
|
||||
Dim saltBytes = New Byte(nSalt) {}
|
||||
|
||||
Using provider = New RNGCryptoServiceProvider()
|
||||
provider.GetNonZeroBytes(saltBytes)
|
||||
End Using
|
||||
|
||||
Return Convert.ToBase64String(saltBytes)
|
||||
Return saltBytes
|
||||
'Convert.ToBase64String(saltBytes)
|
||||
End Function
|
||||
Public Shared Async Function HashPassword(ByVal password As String, ByVal salt As Byte(), ByVal nIterations As Integer, ByVal nHash As Integer) As Threading.Tasks.Task(Of Byte())
|
||||
Dim Argon As Argon2id = New Argon2id(Encoding.UTF8.GetBytes(password))
|
||||
Argon.Salt = salt
|
||||
Argon.DegreeOfParallelism = 6
|
||||
Argon.Iterations = nIterations
|
||||
Argon.MemorySize = 4096
|
||||
Return Await Argon.GetBytesAsync(nHash)
|
||||
'Return Convert.ToBase64String(Argon.GetBytes(nHash))
|
||||
Return Argon.GetBytes(nHash)
|
||||
'Dim saltBytes = Convert.FromBase64String(salt)
|
||||
'Using rfc2898DeriveBytes = New Rfc2898DeriveBytes(password, saltBytes, nIterations)
|
||||
'End Using
|
||||
End Function
|
||||
Public Shared Function HashPassword(ByVal password As String, ByVal salt As String, ByVal nIterations As Integer, ByVal nHash As Integer) As String
|
||||
Dim saltBytes = Convert.FromBase64String(salt)
|
||||
|
||||
Using rfc2898DeriveBytes = New Rfc2898DeriveBytes(password, saltBytes, nIterations)
|
||||
Return Convert.ToBase64String(rfc2898DeriveBytes.GetBytes(nHash))
|
||||
End Using
|
||||
Public Shared Async Function Verifyhash(ByVal passw As String, ByVal salt As Byte(), ByVal hash As Byte(), ByVal nIterations As Integer, ByVal nHash As Integer) As Threading.Tasks.Task(Of Boolean)
|
||||
Dim newHash As Byte() = Await HashPassword(passw, salt, nIterations, nHash)
|
||||
Return hash.SequenceEqual(newHash)
|
||||
End Function
|
||||
|
||||
Public Shared Function RandomInteger(ByVal min As Integer, ByVal _
|
||||
max As Integer) As Integer
|
||||
Dim rand As New RNGCryptoServiceProvider()
|
||||
Dim one_byte() As Byte = {0}
|
||||
rand.GetBytes(one_byte)
|
||||
Return min + (max - min) * (one_byte(0) / 255)
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user