|
-
Dec 14th, 2023, 05:39 AM
#1
Thread Starter
Addicted Member
C# convert multi bytes to VB.NET
Hello can someone help me how i can convert this line: (byte[] salt, byte[] verifier) = GetSRP6RegistrationData(username,password);
Code:
public static void Main(string[] args)
{
string username = "test";
string password = "passwor";
(byte[] salt, byte[] verifier) = GetSRP6RegistrationData(username,password);
using (var connection = new MySqlConnection("server=127.0.0.1;database=acore_auth;user=root;password=pass;"));
{
connection.Open();
using (var command = new MySqlCommand("Insert Into account (username,salt,verifier) VALUES (@username, @salt, @verifier)". connection))
{
Command.Parameters.AddWithValue("@Username", username.ToUpper());
Command.Parameters.AddWithValue("@Salt", salt);
Command.Parameters.AddWithValue("@Verifier", verifier);
command.ExecuteNonQuery();
}
}
}
and class
Code:
public static (byte[] Salt, byte[] Verifier) GetSRP6RegistrationData(string username,string password)
{
byte[] salt = new byte[32];
var rng = RandomNumberGenerator.Create();
rng.GetBytes(salt);
rng.Dispose();
byte[] verifier = CalculateSRP6Verifier(username,password,salt);
return (salt,verifier);
}
class converted:
Code:
Public Shared Function GetSRP6RegistrationData(username As String, password As String) As (Salt As Byte(), Verifier As Byte())
Dim salt As Byte() = New Byte(31) {}
Dim rng = RandomNumberGenerator.Create()
rng.GetBytes(salt)
rng.Dispose()
Dim verifier As Byte() = CalculateSRP6Verifier(username, password, salt)
Return (salt, verifier)
End Function
Last edited by luckydead; Dec 14th, 2023 at 05:42 AM.
-
Dec 14th, 2023, 06:32 AM
#2
Re: C# convert multi bytes to VB.NET
 Originally Posted by luckydead
Hello can someone help me how i can convert this line: (byte[] salt, byte[] verifier) = GetSRP6RegistrationData(username,password);
You may assign a variable from the function call that holds the Tuple and it's two elements Salt and Verifier.
Code:
Dim result = GetSRP6RegistrationData(username,password)
'Access the Tuple's elements Salt and Verifer and perform operation blah3x....
'result.Salt
'result.Verifier
See topic Tuples as method return values here
-
Dec 14th, 2023, 06:44 AM
#3
Thread Starter
Addicted Member
Re: C# convert multi bytes to VB.NET
 Originally Posted by KGComputers
You may assign a variable from the function call that holds the Tuple and it's two elements Salt and Verifier.
Code:
Dim result = GetSRP6RegistrationData(username,password)
'Access the Tuple's elements Salt and Verifer and perform operation blah3x....
'result.Salt
'result.Verifier
See topic Tuples as method return values here
you mean will become like this:
Code:
Public Shared Function GetSRP6RegistrationData(username As String, password As String) As Tuple(Of Byte(), Byte())
Dim salt As Byte() = New Byte(32) {}
Using rng = RandomNumberGenerator.Create()
rng.GetBytes(salt)
End Using
Dim verifier As Byte() = CalculateSRP6Verifier(username, password, salt)
'Return {salt, verifier}
Return Tuple.Create(salt, verifier)
End Function
-
Dec 15th, 2023, 02:40 AM
#4
Re: C# convert multi bytes to VB.NET
 Originally Posted by luckydead
you mean will become like this:
Code:
Public Shared Function GetSRP6RegistrationData(username As String, password As String) As Tuple(Of Byte(), Byte())
Dim salt As Byte() = New Byte(32) {}
Using rng = RandomNumberGenerator.Create()
rng.GetBytes(salt)
End Using
Dim verifier As Byte() = CalculateSRP6Verifier(username, password, salt)
'Return {salt, verifier}
Return Tuple.Create(salt, verifier)
End Function
Hello can someone help me how I can convert this line: (byte[] salt, byte[] verifier) = GetSRP6RegistrationData(username,password);
Since you are concern with calling the GetSRP6RegistrationData() function that returns tuple and it's elements in your first post, you don't have to modify the GetSRP6RegistrationData() function. In your Sub Main() function, call the GetSRP6RegistrationData() and assign it to a variable. You can then access the two elements Salt and Verifier from that variable and their values and perform the database logic from there.
Code:
Sub Main(args As String())
Dim username As String = "test"
Dim password As String = "passwor"
' how I can convert this line: (byte[] salt, byte[] verifier) = GetSRP6RegistrationData(username,password);
Dim result = GetSRP6RegistrationData(username, password)
'Access the Tuple's elements Salt and Verifer and perform operation blah3x....
Using connection As New MySqlConnection("server=127.0.0.1;database=acore_auth;user=root;password=pass;")
'...more codes here
Command.Parameters.AddWithValue("@Salt", result.Salt)
Command.Parameters.AddWithValue("@Verifier", result.Verifier)
End Using
End Sub
Public Function GetSRP6RegistrationData(username As String, password As String) As (Salt As Byte(), Verifier As Byte())
Dim salt As Byte() = New Byte(31) {}
Dim rng = RandomNumberGenerator.Create()
rng.GetBytes(salt)
rng.Dispose()
'commented out since I don't have code for CalculateSRP6Verifier()
'Dim verifier As Byte() = CalculateSRP6Verifier(username, password, salt)
Dim verifier As Byte()
Return (salt, verifier)
End Function
Last edited by KGComputers; Dec 15th, 2023 at 03:28 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|