convert code from VB to VB.Net

hi,

I have both an offline application (done with Visual Basic 6.0 )

and an online application (thru ASP.Net 2.0 and Visual Basic as code behind).

Right now, I have a code in Visual Basic for encrypting a file. This is working in my offline

application.

However, when I used the code in my online application, it got some errors in it.

Maybe incompatibility with the language used.

Is there any way I can convert my VB code to VB.Net?

Thanks a lot.

Sheila 

 


Rock on!!!
0
sheila_rt
4/13/2007 8:13:46 AM
asp.net.visual-basic.net 3721 articles. 0 followers. Follow

23 Replies
1334 Views

Similar Articles

[PageSpeed] 29

Get the VB6 code advisor from http://msdn2.microsoft.com/en-gb/vbasic/ms789135.aspx and check you existing code base prior to conversion.

Make a copy of your VB6 project and open it in Visual Studio; it should offer to convert the project for you.

Also look at the web cast at http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?culture=en-US&EventID=1032308930&CountryCode=US 

There is a free e-book on VB.NET at http://msdn2.microsoft.com/en-gb/vbasic/ms789094.aspx

 


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
TATWORTH
4/13/2007 8:42:35 PM
You could probably post the code here as well and many of us can probably help translate it.  There are a few different things in VB.NETcompared to VB that will not translate exactly the same even in modules.
Picky
0
pickyh3d
4/13/2007 9:04:19 PM

hi,

I got this code from a certain website.

Its for encrypting / decrypting text using the Rijndael algorithm.

ModCryptText.bas

Option Explicit
'   encrypt text messages using AES_Rijndael Block Cipher
'   by Dipankar Basu.
Private oTest  As CRijndael
Public Function strEncrypt(ByVal strMsg As String, ByVal pKey As String) As String
Dim ByteArray() As Byte, byteKey() As Byte, CryptText() As Byte
    On Local Error Resume Next
'   If strMsg = vbNullString Or pKey = vbNullString Then Exit Function
    Set oTest = New CRijndael
    ByteArray() = StrConv(strMsg, vbFromUnicode)
    byteKey() = StrConv(pKey, vbFromUnicode)
    CryptText() = oTest.EncryptData(ByteArray(), byteKey())
    Set oTest = Nothing
    strEncrypt = StrConv(CryptText(), vbUnicode)
End Function
Public Function strDecrypt(ByVal strMsg As String, ByVal pKey As String) As String
Dim ByteArray() As Byte, byteKey() As Byte, CryptText() As Byte
    On Local Error Resume Next
'   If strMsg = vbNullString Or pKey = vbNullString Then Exit Function
    Set oTest = New CRijndael
    ByteArray() = StrConv(strMsg, vbFromUnicode)
    byteKey() = StrConv(pKey, vbFromUnicode)
    CryptText() = oTest.DecryptData(ByteArray(), byteKey())
    Set oTest = Nothing
    strDecrypt = StrConv(CryptText(), vbUnicode)
End Function
Public Function Hex2Str(ByVal strData As String)
Dim i As Long, CryptString As String, tmpChar As String
    On Local Error Resume Next
    For i = 1 To Len(strData) Step 2
        CryptString = CryptString & Chr$(Val("&H" & Mid$(strData, i, 2)))
    Next i
    Hex2Str = CryptString
End Function
Public Function Str2Hex(ByVal strData As String)
Dim i As Long, CryptString As String, tmpAppend As String
    On Local Error Resume Next
    For i = 1 To Len(strData)
        tmpAppend = Hex$(Asc(Mid$(strData, i, 1)))
        If Len(tmpAppend) = 1 Then tmpAppend = Trim$(Str$(0)) & tmpAppend
        CryptString = CryptString & tmpAppend: DoEvents
    Next i
    Str2Hex = CryptString
End Function
Public Function FileExists(ByVal sFilename As String) As Boolean
Dim Fl As Integer: Fl = Len(Dir$(sFilename))
    On Local Error Resume Next
    FileExists = IIf(Err Or Fl = 0, False, True)
End Function
Private Function GenRaND() As Byte
Dim RandomSeed As Integer
    Randomize
    RandomSeed = Int(Rnd * 3) + 1
    If RandomSeed = 1 Then
        GenRaND = Int(26 * Rnd + 65)
    ElseIf RandomSeed = 2 Then
        GenRaND = Int(26 * Rnd + 97)
    Else ' RandomSeed = 3 Then
        GenRaND = Int(10 * Rnd + 48)
    End If
End Function
Public Function GenKey(ByVal PassLength As Integer) As String
Dim tempPassword As String, i As Integer
    For i = 1 To PassLength
        tempPassword = tempPassword & Chr$(GenRaND)
    Next i
    GenKey = tempPassword
End Function
'Copyright (c)2003 by Dipankar Basu
' http://www.geocities.com/basudip_in/

 

Crijndael.cls

'   Credits :      Phil Fresle
Option Explicit
Private m_lOnBits(30)    As Long
Private m_l2Power(30)    As Long
Private m_bytOnBits(7)   As Byte
Private m_byt2Power(7)   As Byte
Private m_InCo(3)        As Byte
Private m_fbsub(255)     As Byte
Private m_rbsub(255)     As Byte
Private m_ptab(255)      As Byte
Private m_ltab(255)      As Byte
Private m_ftable(255)    As Long
Private m_rtable(255)    As Long
Private m_rco(29)        As Long
Private m_Nk             As Long
Private m_Nb             As Long
Private m_Nr             As Long
Private m_fi(23)         As Byte
Private m_ri(23)         As Byte
Private m_fkey(119)      As Long
Private m_rkey(119)      As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Any, ByVal Source As Any, ByVal Length As Long)
Private Sub Class_Initialize()
    m_InCo(0) = &HB:    m_InCo(1) = &HD
    m_InCo(2) = &H9:    m_InCo(3) = &HE
    m_bytOnBits(0) = 1          ' 00000001
    m_bytOnBits(1) = 3          ' 00000011
    m_bytOnBits(2) = 7          ' 00000111
    m_bytOnBits(3) = 15         ' 00001111
    m_bytOnBits(4) = 31         ' 00011111
    m_bytOnBits(5) = 63         ' 00111111
    m_bytOnBits(6) = 127        ' 01111111
    m_bytOnBits(7) = 255        ' 11111111
    m_byt2Power(0) = 1          ' 00000001
    m_byt2Power(1) = 2          ' 00000010
    m_byt2Power(2) = 4          ' 00000100
    m_byt2Power(3) = 8          ' 00001000
    m_byt2Power(4) = 16         ' 00010000
    m_byt2Power(5) = 32         ' 00100000
    m_byt2Power(6) = 64         ' 01000000
    m_byt2Power(7) = 128        ' 10000000
    m_lOnBits(0) = 1            ' 00000000000000000000000000000001
    m_lOnBits(1) = 3            ' 00000000000000000000000000000011
    m_lOnBits(2) = 7            ' 00000000000000000000000000000111
    m_lOnBits(3) = 15           ' 00000000000000000000000000001111
    m_lOnBits(4) = 31           ' 00000000000000000000000000011111
    m_lOnBits(5) = 63           ' 00000000000000000000000000111111
    m_lOnBits(6) = 127          ' 00000000000000000000000001111111
    m_lOnBits(7) = 255          ' 00000000000000000000000011111111
    m_lOnBits(8) = 511          ' 00000000000000000000000111111111
    m_lOnBits(9) = 1023         ' 00000000000000000000001111111111
    m_lOnBits(10) = 2047        ' 00000000000000000000011111111111
    m_lOnBits(11) = 4095        ' 00000000000000000000111111111111
    m_lOnBits(12) = 8191        ' 00000000000000000001111111111111
    m_lOnBits(13) = 16383       ' 00000000000000000011111111111111
    m_lOnBits(14) = 32767       ' 00000000000000000111111111111111
    m_lOnBits(15) = 65535       ' 00000000000000001111111111111111
    m_lOnBits(16) = 131071      ' 00000000000000011111111111111111
    m_lOnBits(17) = 262143      ' 00000000000000111111111111111111
    m_lOnBits(18) = 524287      ' 00000000000001111111111111111111
    m_lOnBits(19) = 1048575     ' 00000000000011111111111111111111
    m_lOnBits(20) = 2097151     ' 00000000000111111111111111111111
    m_lOnBits(21) = 4194303     ' 00000000001111111111111111111111
    m_lOnBits(22) = 8388607     ' 00000000011111111111111111111111
    m_lOnBits(23) = 16777215    ' 00000000111111111111111111111111
    m_lOnBits(24) = 33554431    ' 00000001111111111111111111111111
    m_lOnBits(25) = 67108863    ' 00000011111111111111111111111111
    m_lOnBits(26) = 134217727   ' 00000111111111111111111111111111
    m_lOnBits(27) = 268435455   ' 00001111111111111111111111111111
    m_lOnBits(28) = 536870911   ' 00011111111111111111111111111111
    m_lOnBits(29) = 1073741823  ' 00111111111111111111111111111111
    m_lOnBits(30) = 2147483647  ' 01111111111111111111111111111111
    m_l2Power(0) = 1            ' 00000000000000000000000000000001
    m_l2Power(1) = 2            ' 00000000000000000000000000000010
    m_l2Power(2) = 4            ' 00000000000000000000000000000100
    m_l2Power(3) = 8            ' 00000000000000000000000000001000
    m_l2Power(4) = 16           ' 00000000000000000000000000010000
    m_l2Power(5) = 32           ' 00000000000000000000000000100000
    m_l2Power(6) = 64           ' 00000000000000000000000001000000
    m_l2Power(7) = 128          ' 00000000000000000000000010000000
    m_l2Power(8) = 256          ' 00000000000000000000000100000000
    m_l2Power(9) = 512          ' 00000000000000000000001000000000
    m_l2Power(10) = 1024        ' 00000000000000000000010000000000
    m_l2Power(11) = 2048        ' 00000000000000000000100000000000
    m_l2Power(12) = 4096        ' 00000000000000000001000000000000
    m_l2Power(13) = 8192        ' 00000000000000000010000000000000
    m_l2Power(14) = 16384       ' 00000000000000000100000000000000
    m_l2Power(15) = 32768       ' 00000000000000001000000000000000
    m_l2Power(16) = 65536       ' 00000000000000010000000000000000
    m_l2Power(17) = 131072      ' 00000000000000100000000000000000
    m_l2Power(18) = 262144      ' 00000000000001000000000000000000
    m_l2Power(19) = 524288      ' 00000000000010000000000000000000
    m_l2Power(20) = 1048576     ' 00000000000100000000000000000000
    m_l2Power(21) = 2097152     ' 00000000001000000000000000000000
    m_l2Power(22) = 4194304     ' 00000000010000000000000000000000
    m_l2Power(23) = 8388608     ' 00000000100000000000000000000000
    m_l2Power(24) = 16777216    ' 00000001000000000000000000000000
    m_l2Power(25) = 33554432    ' 00000010000000000000000000000000
    m_l2Power(26) = 67108864    ' 00000100000000000000000000000000
    m_l2Power(27) = 134217728   ' 00001000000000000000000000000000
    m_l2Power(28) = 268435456   ' 00010000000000000000000000000000
    m_l2Power(29) = 536870912   ' 00100000000000000000000000000000
    m_l2Power(30) = 1073741824  ' 01000000000000000000000000000000
End Sub
Private Function LShift(ByVal lValue As Long, ByVal iShiftBits As Integer) As Long
    If iShiftBits = 0 Then
        LShift = lValue:        Exit Function
    ElseIf iShiftBits = 31 Then
        LShift = IIf(lValue And 1, &H80000000, 0)
        Exit Function
    ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
        Err.Raise 6
    End If
    If (lValue And m_l2Power(31 - iShiftBits)) Then
        LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
    Else
        LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
    End If
End Function
Private Function RShift(ByVal lValue As Long, ByVal iShiftBits As Integer) As Long
    If iShiftBits = 0 Then
        RShift = lValue:        Exit Function
    ElseIf iShiftBits = 31 Then
        RShift = IIf(lValue And &H80000000, 1, 0)
        Exit Function
    ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
        Err.Raise 6
    End If
    RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)
    If (lValue And &H80000000) Then RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
End Function
Private Function LShiftByte(ByVal bytValue As Byte, ByVal bytShiftBits As Byte) As Byte
    If bytShiftBits = 0 Then
        LShiftByte = bytValue:        Exit Function
    ElseIf bytShiftBits = 7 Then
        LShiftByte = IIf(bytValue And 1, &H80, 0)
        Exit Function
    ElseIf bytShiftBits < 0 Or bytShiftBits > 7 Then
        Err.Raise 6
    End If
    LShiftByte = ((bytValue And m_bytOnBits(7 - bytShiftBits)) * m_byt2Power(bytShiftBits))
End Function
Private Function RShiftByte(ByVal bytValue As Byte, ByVal bytShiftBits As Byte) As Byte
    If bytShiftBits = 0 Then
        RShiftByte = bytValue:        Exit Function
    ElseIf bytShiftBits = 7 Then
        RShiftByte = IIf(bytValue And &H80, 1, 0)
        Exit Function
    ElseIf bytShiftBits < 0 Or bytShiftBits > 7 Then
        Err.Raise 6
    End If
    RShiftByte = bytValue \ m_byt2Power(bytShiftBits)
End Function
Private Function RotateLeft(ByVal lValue As Long, ByVal iShiftBits As Integer) As Long
    RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits))
End Function
Private Function RotateLeftByte(ByVal bytValue As Byte, ByVal bytShiftBits As Byte) As Byte
    RotateLeftByte = LShiftByte(bytValue, bytShiftBits) Or RShiftByte(bytValue, (8 - bytShiftBits))
End Function
Private Function Pack(b() As Byte) As Long
Dim lCount As Long, lTemp  As Long
    For lCount = 0 To 3
        lTemp = b(lCount): Pack = Pack Or LShift(lTemp, (lCount * 8))
    Next lCount
End Function
Private Function PackFrom(b() As Byte, ByVal k As Long) As Long
Dim lCount As Long, lTemp  As Long
    For lCount = 0 To 3
        lTemp = b(lCount + k): PackFrom = PackFrom Or LShift(lTemp, (lCount * 8))
    Next lCount
End Function
Private Sub Unpack(ByVal a As Long, b() As Byte)
    b(0) = a And m_lOnBits(7)
    b(1) = RShift(a, 8) And m_lOnBits(7)
    b(2) = RShift(a, 16) And m_lOnBits(7)
    b(3) = RShift(a, 24) And m_lOnBits(7)
End Sub
Private Sub UnpackFrom(ByVal a As Long, b() As Byte, ByVal k As Long)
    b(0 + k) = a And m_lOnBits(7)
    b(1 + k) = RShift(a, 8) And m_lOnBits(7)
    b(2 + k) = RShift(a, 16) And m_lOnBits(7)
    b(3 + k) = RShift(a, 24) And m_lOnBits(7)
End Sub
Private Function Xtime(ByVal a As Byte) As Byte
Dim b As Byte:    b = IIf(a And &H80, &H1B, 0)
    a = LShiftByte(a, 1):   a = a Xor b:   Xtime = a
End Function
Private Function Bmul(ByVal x As Byte, y As Byte) As Byte
    If x <> 0 And y <> 0 Then
        Bmul = m_ptab((CLng(m_ltab(x)) + CLng(m_ltab(y))) Mod 255)
    Else
        Bmul = 0
    End If
End Function
Private Function SubByte(ByVal a As Long) As Long
Dim b(3) As Byte
    Unpack a, b
    b(0) = m_fbsub(b(0)):    b(1) = m_fbsub(b(1))
    b(2) = m_fbsub(b(2)):    b(3) = m_fbsub(b(3))
    SubByte = Pack(b)
End Function
Private Function Product(ByVal x As Long, ByVal y As Long) As Long
Dim xb(3) As Byte, yb(3) As Byte
    Unpack x, xb:    Unpack y, yb
    Product = Bmul(xb(0), yb(0)) Xor Bmul(xb(1), yb(1)) Xor Bmul(xb(2), yb(2)) Xor Bmul(xb(3), yb(3))
End Function
Private Function InvMixCol(ByVal x As Long) As Long
Dim y       As Long, m       As Long, b(3)    As Byte
    m = Pack(m_InCo)
    b(3) = Product(m, x):    m = RotateLeft(m, 24)
    b(2) = Product(m, x):    m = RotateLeft(m, 24)
    b(1) = Product(m, x):    m = RotateLeft(m, 24)
    b(0) = Product(m, x):    y = Pack(b)
    InvMixCol = y
End Function
Private Function ByteSub(ByVal x As Byte) As Byte
Dim y As Byte
    y = m_ptab(255 - m_ltab(x)):    x = y
    x = RotateLeftByte(x, 1):       y = y Xor x
    x = RotateLeftByte(x, 1):       y = y Xor x
    x = RotateLeftByte(x, 1):       y = y Xor x
    x = RotateLeftByte(x, 1):       y = y Xor x
    y = y Xor &H63:              ByteSub = y
End Function
Private Sub gentables()
Dim i    As Long, y As Byte
Dim b(3) As Byte, ib As Byte
    m_ltab(0) = 0:    m_ptab(0) = 1
    m_ltab(1) = 0:    m_ptab(1) = 3
    m_ltab(3) = 1
    For i = 2 To 255
        m_ptab(i) = m_ptab(i - 1) Xor Xtime(m_ptab(i - 1))
        m_ltab(m_ptab(i)) = i
    Next i
    m_fbsub(0) = &H63:    m_rbsub(&H63) = 0
    For i = 1 To 255
        ib = i:        y = ByteSub(ib)
        m_fbsub(i) = y:        m_rbsub(y) = i
    Next i
    y = 1
    For i = 0 To 29
        m_rco(i) = y:        y = Xtime(y)
    Next i
    For i = 0 To 255
        y = m_fbsub(i):        b(3) = y Xor Xtime(y)
        b(2) = y:               b(1) = y
        b(0) = Xtime(y):        m_ftable(i) = Pack(b)
        y = m_rbsub(i):        b(3) = Bmul(m_InCo(0), y)
        b(2) = Bmul(m_InCo(1), y): b(1) = Bmul(m_InCo(2), y)
        b(0) = Bmul(m_InCo(3), y): m_rtable(i) = Pack(b)
    Next i
End Sub
Private Sub gkey(ByVal nb As Long, ByVal nk As Long, Key() As Byte)
Dim i            As Long, j As Long, k As Long, m As Long
Dim N            As Long, C1 As Long, C2 As Long, C3 As Long
Dim CipherKey(7) As Long
    m_Nb = nb:    m_Nk = nk
    If m_Nb >= m_Nk Then
        m_Nr = 6 + m_Nb
    Else
        m_Nr = 6 + m_Nk
    End If
    C1 = 1
    If m_Nb < 8 Then
        C2 = 2:        C3 = 3
    Else
        C2 = 3:        C3 = 4
    End If
    For j = 0 To nb - 1
        m = j * 3
        m_fi(m) = (j + C1) Mod nb
        m_fi(m + 1) = (j + C2) Mod nb
        m_fi(m + 2) = (j + C3) Mod nb
        m_ri(m) = (nb + j - C1) Mod nb
        m_ri(m + 1) = (nb + j - C2) Mod nb
        m_ri(m + 2) = (nb + j - C3) Mod nb
    Next j
    N = m_Nb * (m_Nr + 1)
    For i = 0 To m_Nk - 1
        j = i * 4:        CipherKey(i) = PackFrom(Key, j)
    Next i
    For i = 0 To m_Nk - 1
        m_fkey(i) = CipherKey(i)
    Next i
    j = m_Nk:    k = 0
    Do While j < N
        m_fkey(j) = m_fkey(j - m_Nk) Xor SubByte(RotateLeft(m_fkey(j - 1), 24)) Xor m_rco(k)
        If m_Nk <= 6 Then
            i = 1
            Do While i < m_Nk And (i + j) < N
                m_fkey(i + j) = m_fkey(i + j - m_Nk) Xor m_fkey(i + j - 1): i = i + 1
            Loop
        Else
            i = 1
            Do While i < 4 And (i + j) < N
                m_fkey(i + j) = m_fkey(i + j - m_Nk) Xor m_fkey(i + j - 1): i = i + 1
            Loop
            If j + 4 < N Then
                m_fkey(j + 4) = m_fkey(j + 4 - m_Nk) Xor SubByte(m_fkey(j + 3))
            End If
            i = 5
            Do While i < m_Nk And (i + j) < N
                m_fkey(i + j) = m_fkey(i + j - m_Nk) Xor m_fkey(i + j - 1): i = i + 1
            Loop
        End If
        j = j + m_Nk:        k = k + 1
    Loop
    For j = 0 To m_Nb - 1
        m_rkey(j + N - nb) = m_fkey(j)
    Next j
    i = m_Nb
    Do While i < N - m_Nb
        k = N - m_Nb - i
        For j = 0 To m_Nb - 1
            m_rkey(k + j) = InvMixCol(m_fkey(i + j))
        Next j
        i = i + m_Nb
    Loop
    j = N - m_Nb
    Do While j < N
        m_rkey(j - N + m_Nb) = m_fkey(j):        j = j + 1
    Loop
End Sub
Private Sub Encrypt(Buff() As Byte)
Dim i    As Long, j As Long, k As Long, m As Long
Dim a(7) As Long, b(7) As Long, x() As Long
Dim y()  As Long, t() As Long
    For i = 0 To m_Nb - 1
        j = i * 4: a(i) = PackFrom(Buff, j): a(i) = a(i) Xor m_fkey(i)
    Next i
    k = m_Nb:    x = a:    y = b
    For i = 1 To m_Nr - 1
        For j = 0 To m_Nb - 1
            m = j * 3
            y(j) = m_fkey(k) Xor m_ftable(x(j) And m_lOnBits(7)) Xor RotateLeft(m_ftable(RShift(x(m_fi(m)), 8) And m_lOnBits(7)), 8) Xor RotateLeft(m_ftable(RShift(x(m_fi(m + 1)), 16) And m_lOnBits(7)), 16) Xor RotateLeft(m_ftable(RShift(x(m_fi(m + 2)), 24) And m_lOnBits(7)), 24)
            k = k + 1
        Next j
        t = x:        x = y:        y = t
    Next i
    For j = 0 To m_Nb - 1
        m = j * 3
        y(j) = m_fkey(k) Xor m_fbsub(x(j) And m_lOnBits(7)) Xor RotateLeft(m_fbsub(RShift(x(m_fi(m)), 8) And m_lOnBits(7)), 8) Xor RotateLeft(m_fbsub(RShift(x(m_fi(m + 1)), 16) And m_lOnBits(7)), 16) Xor RotateLeft(m_fbsub(RShift(x(m_fi(m + 2)), 24) And m_lOnBits(7)), 24)
        k = k + 1
    Next j
    For i = 0 To m_Nb - 1
        j = i * 4: UnpackFrom y(i), Buff, j: x(i) = 0: y(i) = 0
    Next i
End Sub
Private Sub Decrypt(Buff() As Byte)
Dim i    As Long, j As Long, k As Long, m As Long
Dim a(7) As Long, b(7) As Long, x() As Long
Dim y()  As Long, t() As Long
    For i = 0 To m_Nb - 1
        j = i * 4: a(i) = PackFrom(Buff, j): a(i) = a(i) Xor m_rkey(i)
    Next i
    k = m_Nb:    x = a:    y = b
    For i = 1 To m_Nr - 1
        For j = 0 To m_Nb - 1
            m = j * 3
            y(j) = m_rkey(k) Xor m_rtable(x(j) And m_lOnBits(7)) Xor RotateLeft(m_rtable(RShift(x(m_ri(m)), 8) And m_lOnBits(7)), 8) Xor RotateLeft(m_rtable(RShift(x(m_ri(m + 1)), 16) And m_lOnBits(7)), 16) Xor RotateLeft(m_rtable(RShift(x(m_ri(m + 2)), 24) And m_lOnBits(7)), 24)
            k = k + 1
        Next j
        t = x:        x = y:        y = t
    Next i
    For j = 0 To m_Nb - 1
        m = j * 3
        y(j) = m_rkey(k) Xor m_rbsub(x(j) And m_lOnBits(7)) Xor RotateLeft(m_rbsub(RShift(x(m_ri(m)), 8) And m_lOnBits(7)), 8) Xor RotateLeft(m_rbsub(RShift(x(m_ri(m + 1)), 16) And m_lOnBits(7)), 16) Xor RotateLeft(m_rbsub(RShift(x(m_ri(m + 2)), 24) And m_lOnBits(7)), 24)
        k = k + 1
    Next j
    For i = 0 To m_Nb - 1
        j = i * 4: UnpackFrom y(i), Buff, j: x(i) = 0: y(i) = 0
    Next i
End Sub
Private Function IsInitialized(ByRef vArray As Variant) As Boolean
    On Local Error Resume Next
    IsInitialized = IsNumeric(UBound(vArray))
End Function
Public Function EncryptData(bytMessage() As Byte, bytPassword() As Byte) As Byte()
Dim bytKey(31)     As Byte, bytIn() As Byte, bytOut() As Byte
Dim bytTemp(31)    As Byte, lCount As Long, lLength As Long
Dim lEncodedLength As Long, bytLen(3) As Byte, lPosition As Long
    If Not IsInitialized(bytMessage) Then Exit Function
    If Not IsInitialized(bytPassword) Then Exit Function
    For lCount = 0 To UBound(bytPassword)
        bytKey(lCount) = bytPassword(lCount): If lCount = 31 Then Exit For
    Next lCount
    gentables
    gkey 8, 8, bytKey
    lLength = UBound(bytMessage) + 1:    lEncodedLength = lLength + 4
    If lEncodedLength Mod 32 <> 0 Then lEncodedLength = lEncodedLength + 32 - (lEncodedLength Mod 32)
    ReDim bytIn(lEncodedLength - 1):    ReDim bytOut(lEncodedLength - 1)
    CopyMemory VarPtr(bytIn(0)), VarPtr(lLength), 4
    CopyMemory VarPtr(bytIn(4)), VarPtr(bytMessage(0)), lLength
    For lCount = 0 To lEncodedLength - 1 Step 32
        CopyMemory VarPtr(bytTemp(0)), VarPtr(bytIn(lCount)), 32
        Encrypt bytTemp
        CopyMemory VarPtr(bytOut(lCount)), VarPtr(bytTemp(0)), 32
    Next lCount
    EncryptData = bytOut
End Function
Public Function DecryptData(bytIn() As Byte, bytPassword() As Byte) As Byte()
Dim bytMessage()   As Byte, bytKey(31) As Byte, bytOut() As Byte
Dim bytTemp(31)    As Byte, lCount As Long, lLength As Long
Dim lEncodedLength As Long, bytLen(3) As Byte, lPosition As Long
    If Not IsInitialized(bytIn) Then Exit Function
    If Not IsInitialized(bytPassword) Then Exit Function
    lEncodedLength = UBound(bytIn) + 1
    If lEncodedLength Mod 32 <> 0 Then Exit Function
    For lCount = 0 To UBound(bytPassword)
        bytKey(lCount) = bytPassword(lCount):  If lCount = 31 Then Exit For
    Next lCount
    gentables
    gkey 8, 8, bytKey
    ReDim bytOut(lEncodedLength - 1)
    For lCount = 0 To lEncodedLength - 1 Step 32
        CopyMemory VarPtr(bytTemp(0)), VarPtr(bytIn(lCount)), 32
        Decrypt bytTemp
        CopyMemory VarPtr(bytOut(lCount)), VarPtr(bytTemp(0)), 32
    Next lCount
    CopyMemory VarPtr(lLength), VarPtr(bytOut(0)), 4
    If lLength > lEncodedLength - 4 Then Exit Function
    ReDim bytMessage(lLength - 1)
    CopyMemory VarPtr(bytMessage(0)), VarPtr(bytOut(4)), lLength
    DecryptData = bytMessage
End Function

 

 

Thanks!

 

Sheila


Rock on!!!
0
sheila_rt
4/16/2007 12:24:40 AM
hi,
Rock on!!!
0
sheila_rt
4/16/2007 1:38:32 AM

hi,

I have a question.

In using the Visual Web Developer 2005, what kind of Visual Basic is used as code-behind,

Is it the plain Visual Basic (6.0) or VB.Net?

Thanks!

Sheila


Rock on!!!
0
sheila_rt
4/16/2007 1:41:46 AM

Rijndael Cryptography is implemented as part of the .NET Framework.

Anyway, I was thinking it was some small little cryptographic function and not a VB implementation of a major algorithm.  I can't convert this for free, sorry, but I'll convert a little to help you get started, but first I'll mention that all four arrays could easily be created with simple Math.  One tip though is that in VB the colon ( : ) represents a newline... so just delete it and hit enter if you decide to convert this yourself rather than pay someone.

For instance, you could create the array m_lOnBits with this function (where intIndex represents the index you're trying to retrieve):

' replaces m_lOnBits(intIndex) array -- of course you could just copy/paste the arrays
Public Function IntegerOnBits ( ByVal intIndex As Integer ) As Integer

    ' For example:
    '  index = 0
    '  1 << 1 = 2
    '  (1 << 1) - 1 = 1
    '  --
    '  index = 3
    '  1 << 4 = 16
    '  (1 << 4) - 1 = 15
    Return ( 1 << (intIndex + 1) ) - 1

End Function

You could do power of 2 (m_l2Power) also:

' replaces m_l2Power(intIndex)
Public Function Integer2Power ( ByVal intIndex As Integer ) As Integer

    ' For example:
    '  intIndex = 0
    '  1 << 0 = 1 = 2^0
    '  --
    '  intIndex = 1
    '  1 << 1 = 2 = 2^1
    '  --
    '  intIndex = 3
    '  1 << 3 = 8 = 2^3
    Return (1 << intIndex)

End Function

And I'll convert two core functions for you (you could simply replace the function calls to this with the return line, minus the "Return"):

Private Function LShift(ByVal intValue As Integer, ByVal sShiftBits As Short) As Integer

    Return intValue << sShiftBits

End Function

Private Function RShift(ByVal intValue As Integer, ByVal sShiftBits As Short) As Integer

    Return intValue >> sShiftBits

End Function

I'd also suggest that you change the radomize function to a cryptographically random function.


Picky
0
pickyh3d
4/16/2007 3:49:40 AM
sheila_rt:

hi,

I have a question.

In using the Visual Web Developer 2005, what kind of Visual Basic is used as code-behind,

Is it the plain Visual Basic (6.0) or VB.Net?

Thanks!

Sheila

VB.NET.
Picky
0
pickyh3d
4/16/2007 3:51:02 AM

hi,

What do you think is the best approach if I want to have only encryption/decryption program

that can be used both by my VB 6.0 program(offline application) and ASP.Net 2.0 --VB as Code-behind (Visual Web Developer 2k5) (online application).

I heard something about active x dll but I don't have any idea about it.

Any suggestions?

Thanks!

 

Sheila


Rock on!!!
0
sheila_rt
4/17/2007 4:59:44 AM

Compile a DLL and add it as a reference to both projects.

Here's a recent article I found on compiling VB6 DLLs.

http://www.windowsdevcenter.com/pub/a/windows/2005/04/26/create_dll.html?page=1

Let me know if you can't figure it out.


Picky
0
pickyh3d
4/18/2007 1:17:55 AM
hi,
Rock on!!!
0
sheila_rt
4/18/2007 1:45:14 AM

hi,

I was able to make a dll and now my vb.net application can use it.

 My problem now is how to add reference to my vb 6.0 application.

I can't find the COM part where I can locate the dll that I am going to use.

I tried declaring the dll in my vb 6.0 code, but I got an error.

Any idea?

 Thanks!

Sheila


Rock on!!!
0
sheila_rt
4/18/2007 1:49:06 AM

hi,

Declaration is :

Public Declare Function strEncrypt Lib "Rijndael.dll" () As String
Public Declare Function Str2Hex Lib "Rijndael.dll" () As String

where

strEncrypt and  Str2Hex are the functions that I am  going to use.

Rijndael.dll  is the name ofthe dll that I am going to use

Since my OS is Japanese, I can't understand the error message, but the error points to the declaration.

 

 


Rock on!!!
0
sheila_rt
4/18/2007 1:57:45 AM

Don't those functions have parameters?

From above:

Public Function strEncrypt(ByVal strMsg As String, ByVal pKey As String) As String

Public Function Str2Hex(ByVal strData As String)

My guess is that you'd want:

Public Declare Function strEncrypt Lib "Rijndael.dll" ( ByVal strMsg As String, ByVal pKey As String ) As String

Public Declare Function Str2Hex Lib "Rijndael.dll" ( ByVal strData As String ) As String

But it depends on if you changed anything.


Picky
0
pickyh3d
4/18/2007 2:31:13 AM

hi,

I already added those parameters but  when I run the program,

an error occurs, "Can't find the file Rijndael.dll"

The error is in this part

        TableHeader = strEncrypt(TableHeader, sPassword)
        encrypted_header = Str2Hex(TableHeader)
  

Thanks!

 

Sheila


Rock on!!!
0
sheila_rt
4/18/2007 2:59:25 AM
Did you put the DLL file with your VB6 project?
Picky
0
pickyh3d
4/18/2007 3:04:39 AM
hi,
Rock on!!!
0
sheila_rt
4/19/2007 12:27:31 AM

hi,

 

Yeah..I already did...It worked fine now.

Both my VB 6.0 and VB.NET application can now access the strEncrypt function of the DLL.

But, when I call another function strDecrypt, I got an error "Type Mismatched".

 


Rock on!!!
0
sheila_rt
4/19/2007 12:59:53 AM
What are you sending it... and what are the function's parameters?
Picky
0
pickyh3d
4/19/2007 1:13:23 AM

hi,

VB 6 Code:

Public Function CopyDecrypted()
    Dim TableRow As String
    'Dim per_row As String
    Dim decrypt As String
    Dim dc As String
 
        ProgressBar1.Value = 3
        'read input
        Open INIDirectory & "TM0001_sample.csv" For Input As #1
        'write for output
        Open INIDirectory & "TM0001.csv" For Output As #2
        
        Do While Not EOF(1)
        Line Input #1, TableRow
         
             
         'TableRow = per_row
                                
         TableRow = modCrypt.strDecrypt(TableRow)
         
         Print #2, TableRow
        
         Loop
          Close #1
          Close #2
          Kill (INIDirectory & "TM0001_sa.csv")
          ProgressBar1.Value = 4
          
        Exit Function
   
   
End Function
DLL Code:
 
Option Explicit
    Private oTest  As CRijndael
    Dim sTemp           As String
    Dim bytIn()         As Byte
    Dim bytOut()        As Byte
    Dim bytPassword()   As Byte
    Dim bytClear()      As Byte
    Dim lCount          As Long
    Dim lLength         As Long

 Public Function strDecrypt(ByVal stext As String) As String
    
    bytPassword = "pass"

    ' NOTE: we are sending bytOut to be decrypted here. However, it is likely
    ' that we will need to reconstruct bytOut, say from the file it has been dumped
    ' in as a string. If it was dumped out in hex it can be reconstructed like this
    ' where sTemp is the string containing the encrypted data...
    
        lLength = Len(stext)
        ReDim bytOut((lLength \ 2) - 1)
        For lCount = 1 To lLength Step 2
          bytOut(lCount \ 2) = CByte("&H" & Mid(sTemp, lCount, 2))
        Next
      
    ' Decrypt
    bytClear = oTest.DecryptData(bytOut, bytPassword)
    
    ' Quick and dirty conversion back to a string. If we earlier looped using the ASC() function
    ' to get one byte per character, we will now need to do the opposite and loop using
    ' the CHR() function to put the string back together again.
    
    strDecrypt = bytClear

End Function
 
 
Thanks!
 
 
Sheila
 

 
Rock on!!!
0
sheila_rt
4/19/2007 2:43:46 AM

On the DLL line "strDecrypt = bytClear" (the last line in the function) change it to "strDecrypt = StrConv(bytClear, vbUnicode)" .  You may also want to change " bytPassword = "pass" " (top of the function) to "bytPassword = StrConv("pass", vbFromUnicode)" .  At least, that's my first thought.

The bolded non-DLL, VB 6 line looks valid to me.


Picky
0
pickyh3d
4/19/2007 3:07:14 AM

hi,

thanks for the suggestion.

I tried your suggestion but I got the same error again.

A while ago I made another program, a bit similar to my vb project.

Option Explicit

    Dim ModCrypt As New Rijndael_2.ModCrypt

Private Sub cmdEncrypt_Click()

Dim Row As String

Row = txtPlain.Text
    
Row = ModCrypt.strEncrypt(Row)
 
txtEncrypted.Text = Row

'strEncrypt (txtPlain.Text)
cmdDecrypt.Enabled = True
txtPlainAgain.Text = ""

End Sub


Private Sub cmdDecrypt_Click()

Dim Row As String

Row = txtEncrypted.Text
     
Row = ModCrypt.strDecrypt(Row)
 
txtPlainAgain.Text = Row
 
 'strDecrypt (txtEncrypted.Text)
End Sub

 in this program, I used the same dll and it worked just fine. The input string can be encrypted and decrypted.

It's weird...

Sheila

  


Rock on!!!
0
sheila_rt
4/19/2007 4:48:30 AM

That is odd.  In that case, you should check your Crypt Module and make sure the Declare line is correct.  If it is the same DLL, and it works in the other VB6 project, then you have something interacting with it differently somewhere along the line.

You should also turn on Option Explicit in your new VB6 project to try and see if you're attempting to do something implicitly.

Also, one other thing is that your loop for the IO is wrong.

You have a Do-While:

Do While Not EOF(1)

    ' ...

Loop

But, that should be a While loop:

While Not EOF(1)

    ' ...

Wend

You could be getting some broken, jumbled first line of data to start of with, which is breaking the function, instead of the program crashing directly from the IO mistake.

Hopefully that's all it is.


Picky
0
pickyh3d
4/19/2007 2:30:05 PM

hi,

The decrypt function is working fine now.

When I checked again the code in my dll, I noticed that I'm using a different variable.

instead of using stext, I used stemp...

 Public Function strDecrypt(ByVal stext As String) As String
    '||||   Set object to Class CRijndael.cls
    Set oTest = New CRijndael

    '||||   current key value
    bytPassword = "pass"

    '||||   NOTE: we are sending bytOut to be decrypted here. However, it is likely
    '||||   that we will need to reconstruct bytOut, say from the file it has been dumped
    '||||   in as a string. If it was dumped out in hex it can be reconstructed like this
    '||||   where sTemp is the string containing the encrypted data...
        
       '||||   Convert back the passed string from hexadecimal to byte format
        lLength = Len(stext)
        ReDim bytOut((lLength \ 2) - 1)
        For lCount = 1 To lLength Step 2
          bytOut(lCount \ 2) = CByte("&H" & Mid(stemp, lCount, 2))
        Next
   
    '||||   Decrypt the data
    bytClear = oTest.DecryptData(bytOut, bytPassword)
 
   
    '||||   Return the encrypted string
    strDecrypt = bytClear

End Function

 I changed it already. And then I also noticed that I forgot to declare the object for the class CRijndael

    Set oTest = New CRijndael

Those things are the causes of the error.All because of my carelessness.

Anyways, thank you som much for all the help.I really appreate it.

Sheila

 

 


Rock on!!!
0
sheila_rt
4/20/2007 12:38:46 AM
Reply:

Similar Artilces:

What are the diff. visual basic 6 and vb.net ? How to convert the VB6 project to vb.net proj ?
What are the diff. visual basic 6 and vb.net ? How to convert the VB6 project to vb.net proj ? with code and interface too. There are entire forums dedicated to the differences between the two, and to convert your projects you should try the upgrade wizard in Visual Studio....

How to convert C#.Net code to VB.Net code ???...
HI, i was searching something new, then i suddenly find some tips to convert C#.Net code to VB.Net but i did not do well. i am puttint its url here plz tell me how to convert C#.Net code to VB.Net. http://www.dotnetspider.com/code/C-273-Convert-C-VB-NET.aspx Jasim...Please remember to click “Mark as Answer” on the post that helps youJasim AkhtarNew Delhi ( INDIA ) It would be better if you write the problem you having, while converting from C# to VB.NET. You cannot completely rely on online converters. ThanksMark post(s) as "Answer" that helped youElectronic ScrewWebsite||Bl...

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

converting to vb.net from c#.net authorize.net
authorize.net offered me some sample code when I signed up with them the only problem is the sample code is in c#.net but my page that they type all of their credit card into is vb.net <code><%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <script language="C#" runat="server"> void Page_Load(Object Src, EventArgs E) { myPage.Text = readHtmlPage("https://certification.authorize.net/gateway/transact.dll"); } private String readHtmlPage(string url) { ...

converting vb.net 2003 files to vb.net 2005
Hi, i am beginner..i watch videos about vb.net..they made on vs.net 2003 when i wrote these codes in 2005 ,it gives errors..is there any program which convert the code automatically?   thanks,Thanks,Speranza What videos are you talking about?  There are lots of great, up-to-date ASP.NET Videos on this site for free.Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! i am talking about learnvisualstudio.net videos..Thanks,Speranza Speranza:they made on vs.net 2003 when i wrote these codes in 2005 ,it gives errors..is there a...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At http://www.WebLogicArts.com/DemoList.aspx there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

Converting Web Site from Vb.Net 2003 to Vb.Net 2005
I have a web site in vb.net 2003 that I what to convert to vb.net 2005. I open my web site in the visual studio 2005 by Local IIS option. I follow the steps of the visual studio conversion wizard.In the conversion report I received the following warning 'Referencepath' settings have not been converted.  Can anyone tell what I have to do to make this warning disappear? Best regards,Sérgio 'Referencepath'  is a property you can set with with VS2003 project file, sothat when ever you to do Add reference this path is serached for class libraries.  We do not  have that ...

How could i convert this code vb in vb.net?
Dim Report As CRAXDRT.ReportDim ReportSub As CRAXDRT.ReportDim ReportSub1 As CRAXDRT.Report Dim m_crwDatabase As CRAXDRT.Database Dim MaxDetail As IntegerDim MaxMain As Integer Dim PageCountMax As Integer Private Sub Command1_Click()     PayableVoucher "应付款挂帐单", "应付组"        End Sub Private Sub Command2_Click()     Command1.Visible = True    CRViewer1.Visible = False    Command2.Visible = False    Command3.Visible = True    Me.WindowState = 0     ...

Is there a software to convert VB codes to VB.net codes automatically?
hi there! Do anyone of you know if there is any software to convert VB codes to VB.net codes? Or must i maunally convert them? Visual Studio.NET 2000 and 2003 versions automatically convert VB 6 code to VB.NET code, for the most part. Refer to Preparing Your Visual Basic 6.0 Applications for the Upgrade to Visual Basic .NET for more information. Hope this helps, AppanASP.NET Team This posting is provided "AS IS" with no warranties, and confers no rights. thanks! =) Is this case same for Visual C codes? Same concept. Refer to Managed Extensions for C++ Migratio...

Translate c#.net code to vb.net code
Hi I can usually do the translation myself, but this time I am a bit stumped  Let us consider to rewrite Urls (more than 16000 links) using a table. Save original url and rewritten url in a table. Now add a class file in App_Code folder. class UrlRewriteModule : IHttpModule{    public void Dispose()    {        // Nothing to dispose    }    public void Init(HttpApplication context)    {        context.BeginRequest += new EventHandler(context...

Converting from vb.net to c#.net
Hello I have recently purchased VBGolds RawDataPrinter which should allow users to print directly to label printers on our network directly from a c# web form.  Unfortunately they only supply vb.net examples and I have need of c#.  The component has been installed on our web server.  This is some code that they have supplied as examples in vb.net   "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" >"Head1" runat="server&qu...

Visual Studio.Net and VB.Net
Can we install VS.Net and VB.Net on the same machine and work side by. Is there any thing I need to worry about? I use VS.Net enterprise for my office work and I am planning to buy VB.Net standard for my personal use. Before I goahead and buy, I wanted to make sure that it works. Thanks for your help. Anil...

Upgrade VB.net 2002 to VB.net 2003
Hi, i want to upgrade VB.net 2002 to VB.net 2003.what is the procedure?Uninstall 2002 and Install 2003 or something else? VB.net 2003 includes Framework 1.1 or i will install it separately?thanx in advance ...

convert VB.net code to C# code ( Visual studio 2003 )
Hello,   Where can I find a program that convert  VB.net code to C# code ( Visual studio 2003 ) Best regards   Google.***********************Dinakar NethiLife is short. Enjoy it.*********************** http://www.carlosag.net/Tools/CodeTranslator/Default.aspxGO HOKIES!!!...

Web resources about - convert code from VB to VB.Net - asp.net.visual-basic.net

File:Convert to SVG and move to Commons.svg - Wikipedia, the free encyclopedia
As a courtesy (but not a requirement), please e-mail me or leave a note on my talk page if you use this image outside of Wikipedia. Thanks! As ...

Facebook Co-Founder Dustin Moskovitz Sells 450K Shares, Converts 7M More
The great Facebook stock sale frenzy continues on with a report that Co-Founder Dustin Moskovitz unloaded 450,000 shares in the social network ...

Facebook Announces “App2User” Liquidity Program for Merchants to Convert Rewards Points into Credits
... for Credits, just announced a new Credits program called “App2User,” designed to enable merchants and loyalty program operators to convert their ...

How to Convert Leads Into Buying Customers - The 9 Step Sales Process EVERYONE Should Use
... School of Business in Toronto on the topics of Sales and Entrepreneurship. I shared with them the sales process that I find How to Convert Leads ...

Bitcoin : Should I convert my savings to Bitcoin?
Answer (1 of 7): You should think of this question as "Should I invest all my savings in Bitcoin?", and not "Should I have my savings denominated ...

Convertizo 2 - Convert Units and Currency in Style on the App Store on iTunes
Get Convertizo 2 - Convert Units and Currency in Style on the App Store. See screenshots and ratings, and read customer reviews.

Catholics should not convert Jews, says Vatican, in push against anti-Semitism
... 50 years since the Vatican's repudiation of the concept of Jewish guilt for Jesus' death.  Vatican City: Catholics should not try to convert ...

Opinion: These 5 things made me a happy iPad Pro convert
... like I needed a bigger device. But after three weeks with my iPad Pro, several things have changed my mind, and I’m officially a happy convert ...

Today’s apps gone free: BlockBear, Stock Grader, PDF Smart Convert and more
Block ads and other annoying content, take the emotion out of investing, and convert almost anything into a PDF with todays collection of apps ...

How to convert your old VHS tapes to DVD with this software
Remember those old VHS tapes you have sitting in the corner? Convert them into DVDs with this affordable software so you can easily watch them ...

Resources last updated: 12/26/2015 6:16:12 PM