Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

VbScript Function to encode into base64 compatible with .NET function System.Convert.FromBase64String

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
abarberis@gmail.com - 21 Mar 2006 00:15 GMT
I am using the following code to convert a byte array in vbscript which
is passed to a web service:

Function ByteArray2Text(varByteArray)
    'Convert byte array into a string with VBScript
    '60kb = 2 seconds, 100kb = 5 seconds, 200kb = 25 seconds
    Dim strBuffer, lngCounter
    strData = ""
    strBuffer = ""
    For lngCounter = 0 to UBound(varByteArray)
        strBuffer = strBuffer & Chr(255 And Ascb(Midb(varByteArray,lngCounter
+ 1, 1)))
        'Keep strBuffer at 1k bytes maximum
        If lngCounter Mod 1000 = 0 Then
            strData = strData & strBuffer
            strBuffer = ""
        End If
    Next
    ByteArray2Text = strData & strBuffer
End Function

I need to decode it with .NET. It seems that they are different because
I am getting invalid data when I decode using
System.Convert.FromBase64String.

Any ideas? I'm stuck!

Thanks

Alex
abarberis@gmail.com - 21 Mar 2006 00:17 GMT
Sorry wrong function I meant this one:

Function Base64Encode(inData)
 'rfc1521
 '2001 Antonin Foller, Motobit Software, http://Motobit.cz
 Const Base64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
 Dim cOut, sOut, I

 'For each group of 3 bytes
 For I = 1 To Len(inData) Step 3
   Dim nGroup, pOut, sGroup

   'Create one long from this 3 bytes.
   nGroup = &H10000 * Asc(Mid(inData, I, 1)) + _
     &H100 * MyASC(Mid(inData, I + 1, 1)) + MyASC(Mid(inData, I + 2,
1))

   'Oct splits the long To 8 groups with 3 bits
   nGroup = Oct(nGroup)

   'Add leading zeros
   nGroup = String(8 - Len(nGroup), "0") & nGroup

   'Convert To base64
   pOut = Mid(Base64, CLng("&o" & Mid(nGroup, 1, 2)) + 1, 1) + _
     Mid(Base64, CLng("&o" & Mid(nGroup, 3, 2)) + 1, 1) + _
     Mid(Base64, CLng("&o" & Mid(nGroup, 5, 2)) + 1, 1) + _
     Mid(Base64, CLng("&o" & Mid(nGroup, 7, 2)) + 1, 1)

   'Add the part To OutPut string
   sOut = sOut + pOut

   'Add a new line For Each 76 chars In dest (76*3/4 = 57)
   'If (I + 2) Mod 57 = 0 Then sOut = sOut + vbCrLf
 Next
 Select Case Len(inData) Mod 3
   Case 1: '8 bit final
     sOut = Left(sOut, Len(sOut) - 2) + "=="
   Case 2: '16 bit final
     sOut = Left(sOut, Len(sOut) - 1) + "="
 End Select
 Base64Encode = sOut
End Function

Function MyASC(OneChar)
 If OneChar = "" Then MyASC = 0 Else MyASC = Asc(OneChar)
End Function

Can you specify a charcter set in .NET?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.