Anpassungen Variablen/Logik
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
Imports System.Diagnostics
|
||||
Imports Microsoft.VisualBasic
|
||||
Imports Konscious.Security.Cryptography
|
||||
|
||||
Imports System.Threading.Tasks
|
||||
|
||||
Public Class TestPerformance
|
||||
Public Shared Sub createnUsers(ByRef n As Integer)
|
||||
@@ -108,7 +108,6 @@ Public Class TestPerformance
|
||||
con.Close()
|
||||
End Using
|
||||
Next
|
||||
|
||||
End Using
|
||||
End Sub
|
||||
Public Shared Sub DeleteUsers()
|
||||
@@ -116,7 +115,7 @@ Public Class TestPerformance
|
||||
End Sub
|
||||
Public Shared finalzeit As Long
|
||||
|
||||
Public Shared Function TestHashrateServer(zahlint As Integer) As Byte()
|
||||
Public Shared Function TestHashrateServer(zahlint As Integer) As String
|
||||
Dim arrzahl As New List(Of Integer)
|
||||
Dim arrzahl_iterats As New List(Of Integer)
|
||||
Dim hashbytes As New List(Of Byte())
|
||||
@@ -127,11 +126,10 @@ Public Class TestPerformance
|
||||
Dim hashsalts As New List(Of Byte())
|
||||
Dim sw1 As Stopwatch = New Stopwatch
|
||||
Dim sw2 As Stopwatch = New Stopwatch
|
||||
Dim finalhash As Byte()
|
||||
|
||||
For zahl As Integer = 0 To zahlint
|
||||
sw1.Start()
|
||||
hashsalts.Add(VERAG_VARIABLES.GenerateSalt(VERAG_VARIABLES.RandomInteger(Math.Pow(2, 4), Math.Pow(2, 7))))
|
||||
hashsalts.Add(VERAG_VARIABLES.GenerateSalt(VERAG_VARIABLES.RandomInteger(Math.Pow(2, 4), Math.Pow(2, 8))))
|
||||
arrzahl_iterats.Add(VERAG_VARIABLES.getiterationnumber)
|
||||
arrzahl.Add(zahlint)
|
||||
sw1.Stop()
|
||||
@@ -157,9 +155,60 @@ Public Class TestPerformance
|
||||
For Each z3 In arrzeitp3
|
||||
finalarr.Add(hashbytes(z3))
|
||||
Next
|
||||
finalhash = finalarr.Min
|
||||
finalzeit = arrzeitp3.Min
|
||||
Dim finalhashstr As String = Convert.ToBase64String(finalarr.Min)
|
||||
Dim ts As New TimeSpan(0, 0, 0, 0, arrzeitp3.Min)
|
||||
'Dim finlasaltstr As String = Convert.ToBase64String(hashsalts.Min)
|
||||
'Dim finalsalt As String = finlasaltstr
|
||||
Dim finalitertas As String = arrzahl_iterats.Min.ToString
|
||||
'Ausgabe
|
||||
Return finalhash
|
||||
Return "Ergebnisse:" + Environment.NewLine + Space(1) + finalhashstr + Environment.NewLine + Space(1) + Environment.NewLine + "Zeit:" + Space(1) + ts.Hours.ToString + "Stunden:" + ts.Minutes.ToString + "Min:" + ts.Seconds.ToString + "Sekunden" + ts.Milliseconds.ToString + "Millisekunden" + Environment.NewLine + "bei " + Space(1) + finalitertas + Space(1) + "Iterationen."
|
||||
End Function
|
||||
Public Shared Async Function TestHashrateServerAsync(zahlint As Integer) As Task(Of String)
|
||||
Dim arrzahl As New List(Of Integer)
|
||||
Dim arrzahl_iterats As New List(Of Integer)
|
||||
Dim hashbytes As New List(Of Byte())
|
||||
Dim arrzeitp1 As New List(Of Long)
|
||||
Dim arrzeitp2 As New List(Of Long)
|
||||
Dim arrzeitp3 As New List(Of Long)
|
||||
Dim finalarr As New List(Of Byte())
|
||||
Dim hashsalts As New List(Of Byte())
|
||||
Dim sw1 As Stopwatch = New Stopwatch
|
||||
Dim sw2 As Stopwatch = New Stopwatch
|
||||
|
||||
For zahl As Integer = 0 To zahlint
|
||||
sw1.Start()
|
||||
hashsalts.Add(VERAG_VARIABLES.GenerateSalt(VERAG_VARIABLES.RandomInteger(Math.Pow(2, 4), Math.Pow(2, 8))))
|
||||
arrzahl_iterats.Add(VERAG_VARIABLES.getiterationnumber)
|
||||
arrzahl.Add(zahlint)
|
||||
sw1.Stop()
|
||||
arrzeitp1.Add(sw1.ElapsedMilliseconds)
|
||||
sw1.Reset()
|
||||
Next
|
||||
Dim pw As String = "q!V64nS4"
|
||||
For zahl As Integer = 0 To zahlint
|
||||
sw2.Start()
|
||||
hashbytes.Add(Await VERAG_VARIABLES.HashPasswordAsync(pw, hashsalts(zahl), arrzahl_iterats(zahl), arrzahl(zahl)))
|
||||
sw2.Stop()
|
||||
arrzeitp2.Add(sw2.ElapsedMilliseconds)
|
||||
sw2.Reset()
|
||||
Next
|
||||
|
||||
For Each zp1 In arrzeitp1
|
||||
If arrzeitp1(zp1) < arrzeitp2(zp1) Then
|
||||
arrzeitp3.Add(arrzeitp1.Item(zp1))
|
||||
Else
|
||||
arrzeitp3.Add(arrzeitp2.Item(zp1))
|
||||
End If
|
||||
Next
|
||||
For Each z3 In arrzeitp3
|
||||
finalarr.Add(hashbytes(z3))
|
||||
Next
|
||||
Dim finalhashstr As String = Convert.ToBase64String(finalarr.Min)
|
||||
Dim ts As New TimeSpan(0, 0, 0, 0, arrzeitp3.Min)
|
||||
'Dim finlasaltstr As String = Convert.ToBase64String(hashsalts.Min)
|
||||
'Dim finalsalt As String = finlasaltstr
|
||||
Dim finalitertas As String = arrzahl_iterats.Min.ToString
|
||||
'Ausgabe
|
||||
Return "Ergebnisse:" + Environment.NewLine + Space(1) + finalhashstr + Environment.NewLine + "Salt vom Hash:" + Space(1) + Environment.NewLine + "Zeit:" + Space(1) + ts.Hours.ToString + "Stunden:" + ts.Minutes.ToString + "Min:" + ts.Seconds.ToString + "Sekunden" + ts.Milliseconds.ToString + "Millisekunden" + Environment.NewLine + "bei " + Space(1) + finalitertas + "Iterationen."
|
||||
End Function
|
||||
End Class
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
Imports System.Security.Cryptography
|
||||
Imports Microsoft.VisualBasic
|
||||
Imports Konscious.Security.Cryptography
|
||||
Imports System.Threading.Tasks
|
||||
|
||||
Public Class VERAG_VARIABLES
|
||||
Public Shared errornumb As Integer = 0
|
||||
Shared Function getiterationnumber() As Integer
|
||||
@@ -27,6 +29,7 @@ Public Class VERAG_VARIABLES
|
||||
Return saltBytes
|
||||
'Convert.ToBase64String(saltBytes)
|
||||
End Function
|
||||
|
||||
Public Shared Function HashPassword(password As String, salt As Byte(), nIterations As Integer, nHash As Integer) As Byte()
|
||||
'Dim Argon As Argon2id = New Argon2id(Encoding.UTF8.GetBytes(password))
|
||||
|
||||
@@ -41,18 +44,43 @@ Public Class VERAG_VARIABLES
|
||||
Else
|
||||
Dim Argon As Argon2id = New Argon2id(Encoding.UTF8.GetBytes(VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(password)))
|
||||
Argon.Salt = salt
|
||||
Argon.DegreeOfParallelism = 50
|
||||
Argon.DegreeOfParallelism = 24 * (nHash / nHash * 1.03)
|
||||
Argon.Iterations = nIterations * VERAG_VARIABLES.RandomInteger(1, 3)
|
||||
Argon.MemorySize = (((nIterations * 8.485 - (nIterations * 0.56) / 1.85 * 2.28) / 8.28) + 1.024 * 416)
|
||||
Return Argon.GetBytes(nHash)
|
||||
End If
|
||||
|
||||
End Function
|
||||
Public Shared Async Function HashPasswordAsync(password As String, salt As Byte(), nIterations As Integer, nHash As Integer) As Task(Of Byte())
|
||||
'Dim Argon As Argon2id = New Argon2id(Encoding.UTF8.GetBytes(password))
|
||||
|
||||
If HttpContext.Current.Request.ServerVariables("SERVER_NAME") = "localhost" Then
|
||||
Dim Argon As Argon2id = New Argon2id(Encoding.UTF8.GetBytes(VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(password)))
|
||||
Argon.Salt = salt
|
||||
Argon.DegreeOfParallelism = 24
|
||||
Argon.Iterations = nIterations * 2
|
||||
Argon.MemorySize = (((nIterations * 4.98 - (nIterations * 1.23) / 4 * 1.5) / 1.05) + 1 * 290)
|
||||
|
||||
Return Await Argon.GetBytesAsync(nHash)
|
||||
Else
|
||||
Dim Argon As Argon2id = New Argon2id(Encoding.UTF8.GetBytes(VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(password)))
|
||||
Argon.Salt = salt
|
||||
Argon.DegreeOfParallelism = 24 * (nHash / nHash * 1.03)
|
||||
Argon.Iterations = nIterations * VERAG_VARIABLES.RandomInteger(1, 3)
|
||||
Argon.MemorySize = (((nIterations * 8.485 - (nIterations * 0.56) / 1.85 * 2.28) / 8.28) + 1.024 * 416)
|
||||
Return Await Argon.GetBytesAsync(nHash)
|
||||
End If
|
||||
|
||||
End Function
|
||||
|
||||
Public Shared Function Verifyhash(ByVal passw As String, salt As Byte(), ByVal hash As Byte(), ByVal nIterations As Integer, ByVal nHash As Integer) As Boolean
|
||||
Dim newHash As Byte() = HashPassword(passw, salt, nIterations, nHash)
|
||||
Return hash.SequenceEqual(newHash)
|
||||
End Function
|
||||
Public Shared Async Function VerifyhashAsync(ByVal passw As String, salt As Byte(), ByVal hash As Byte(), ByVal nIterations As Integer, ByVal nHash As Integer) As Task(Of Boolean)
|
||||
Dim newHash As Byte() = Await HashPasswordAsync(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}
|
||||
|
||||
Reference in New Issue
Block a user