S
Steve Graddy
I am having a problem converting one line of code in this VB.Net Function.
I have marked the line below in its context. In the converted C# code I am
getting
a error stating "Input string was not in a correct format". Is there anyone
out there
that can shed some light on fixing this line.. I have included the entire
function so
that you may see the context.
The VB.Net line is : lChar = CInt("&H" & Mid(sMD5, (lCount * 2) - 1, 2))
Mod 32
The Converted C# is : lChar = Convert.ToInt32("&H" + Strings.Mid(sMD5,
(lCount * 2) - 1, 2)) % 32;
Thanks for any help sent this way...
Steve Graddy
(e-mail address removed)
********** CODE SNIPPETT
****************************************************
Private Const VALID_CHARS As String = "0123456789ABCDEFGHJKLMNPQRTUVWXY"
Private Const RANDOM_LOWER As Integer = 0
Private Const RANDOM_UPPER As Integer = 31
Public Function GenerateKey(ByRef sAppChars As String) As String
Dim lChar As Integer
Dim lCount As Integer
Dim sInitialChars As String
Dim oMD5 As CMD5
Dim sMD5 As String
Dim sKey As String
Randomize()
' We first generate 9 random characters that are members of VALID_CHARS
sInitialChars = ""
For lCount = 1 To 9
lChar = Int((RANDOM_UPPER - RANDOM_LOWER + 1) * Rnd() + RANDOM_LOWER)
sInitialChars = sInitialChars & Mid(VALID_CHARS, lChar + 1, 1)
Next
' We now get an MD5 of our initial chars plus out application chars
' The application chars should be different for each application to
' ensure that a key for one of our applications is not valid on another
' of our applications. If hackers know we are using this method for
' generating our keys we should ensure that the application character
' are very long to help prevent cracking.
oMD5 = New CMD5
sMD5 = oMD5.MD5(sInitialChars & sAppChars)
oMD5 = Nothing
' We now take each byte-pair from the MD5, convert it back to a byte
' value from the hex code, do a MOD 32, and then select the appropriate
' character from our VALID_CHARS
sKey = sInitialChars
For lCount = 1 To 16
lChar = CInt("&H" & Mid(sMD5, (lCount * 2) - 1, 2)) Mod 32 <--- This
is the line that I can not seem to convert to C#
sKey = sKey & Mid(VALID_CHARS, lChar + 1, 1)
Next
GenerateKey = sKey
End Function
****************************************************************************
*************
I have marked the line below in its context. In the converted C# code I am
getting
a error stating "Input string was not in a correct format". Is there anyone
out there
that can shed some light on fixing this line.. I have included the entire
function so
that you may see the context.
The VB.Net line is : lChar = CInt("&H" & Mid(sMD5, (lCount * 2) - 1, 2))
Mod 32
The Converted C# is : lChar = Convert.ToInt32("&H" + Strings.Mid(sMD5,
(lCount * 2) - 1, 2)) % 32;
Thanks for any help sent this way...
Steve Graddy
(e-mail address removed)
********** CODE SNIPPETT
****************************************************
Private Const VALID_CHARS As String = "0123456789ABCDEFGHJKLMNPQRTUVWXY"
Private Const RANDOM_LOWER As Integer = 0
Private Const RANDOM_UPPER As Integer = 31
Public Function GenerateKey(ByRef sAppChars As String) As String
Dim lChar As Integer
Dim lCount As Integer
Dim sInitialChars As String
Dim oMD5 As CMD5
Dim sMD5 As String
Dim sKey As String
Randomize()
' We first generate 9 random characters that are members of VALID_CHARS
sInitialChars = ""
For lCount = 1 To 9
lChar = Int((RANDOM_UPPER - RANDOM_LOWER + 1) * Rnd() + RANDOM_LOWER)
sInitialChars = sInitialChars & Mid(VALID_CHARS, lChar + 1, 1)
Next
' We now get an MD5 of our initial chars plus out application chars
' The application chars should be different for each application to
' ensure that a key for one of our applications is not valid on another
' of our applications. If hackers know we are using this method for
' generating our keys we should ensure that the application character
' are very long to help prevent cracking.
oMD5 = New CMD5
sMD5 = oMD5.MD5(sInitialChars & sAppChars)
oMD5 = Nothing
' We now take each byte-pair from the MD5, convert it back to a byte
' value from the hex code, do a MOD 32, and then select the appropriate
' character from our VALID_CHARS
sKey = sInitialChars
For lCount = 1 To 16
lChar = CInt("&H" & Mid(sMD5, (lCount * 2) - 1, 2)) Mod 32 <--- This
is the line that I can not seem to convert to C#
sKey = sKey & Mid(VALID_CHARS, lChar + 1, 1)
Next
GenerateKey = sKey
End Function
****************************************************************************
*************