Results 1 to 4 of 4

Thread: C# convert multi bytes to VB.NET

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2017
    Posts
    199

    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.

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: C# convert multi bytes to VB.NET

    Quote Originally Posted by luckydead View Post
    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
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2017
    Posts
    199

    Re: C# convert multi bytes to VB.NET

    Quote Originally Posted by KGComputers View Post
    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

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: C# convert multi bytes to VB.NET

    Quote Originally Posted by luckydead View Post
    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.
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

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
  •  



Click Here to Expand Forum to Full Width