63 lines
2.8 KiB
VB.net
63 lines
2.8 KiB
VB.net
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, 4), Math.Pow(2, 11))
|
|
End Function
|
|
|
|
Shared Sub initerrorcount()
|
|
errornumb = 0
|
|
End Sub
|
|
Shared Sub seterrorcount(var As Integer)
|
|
errornumb = var
|
|
End Sub
|
|
Shared Function geterrornumb() As String
|
|
Return Environment.NewLine + "Error:" + Space(1) + VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(errornumb.ToString) + Space(1)
|
|
End Function
|
|
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 Byte()
|
|
Dim saltBytes = New Byte(nSalt) {}
|
|
Using provider = New RNGCryptoServiceProvider()
|
|
provider.GetNonZeroBytes(saltBytes)
|
|
End Using
|
|
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))
|
|
|
|
If HttpContext.Current.Request.ServerVariables("SERVER_NAME") = "localhost" Then
|
|
Dim Argon As Argon2d = New Argon2d(Encoding.UTF8.GetBytes(VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(password)))
|
|
Argon.Salt = salt
|
|
Argon.DegreeOfParallelism = 24
|
|
Argon.Iterations = nIterations
|
|
Argon.MemorySize = (((nIterations * 1.18 - (nIterations * 1.23) / 4 * 2) / 1.05) + 1 * 270)
|
|
|
|
Return Argon.GetBytes(nHash)
|
|
Else
|
|
Dim Argon As Argon2d = New Argon2d(Encoding.UTF8.GetBytes(VERAG_PROG_ALLGEMEIN.cCryptography3.Encrypt(password)))
|
|
Argon.Salt = salt
|
|
Argon.DegreeOfParallelism = 36
|
|
Argon.Iterations = nIterations * 3
|
|
Argon.MemorySize = (((nIterations * 1.385 - (nIterations * 0.56) / 1.95 * 2.28) / 5.18) + 1.024 * 316)
|
|
Return Argon.GetBytes(nHash)
|
|
End If
|
|
|
|
End Function
|
|
|
|
Public Shared Function Verifyhash(ByVal passw As String, ByVal 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 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
|