Problems coverting TO Base 64 from ASP


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Problems coverting TO Base 64 from ASP

  1. #1
    Join Date
    Dec 2003
    Location
    Italy
    Posts
    250

    Problems coverting TO Base 64 from ASP

    Hello guys,
    I don't understand whet's going on.
    I have an ASP page with a function that converts data to Base 64.
    This ASP is working correctly in Windows 2000 but in Windows 2003 it's not working correctly !!!

    I've developes an ASP.NET app and it works correctly in Windows 2003 !
    But I cant use it because the app is an ASP application, so I must solve the problem in ASP.

    Does anyone knows what could it be ?

    Thank you all !

    The function code is:

    Function Base64Encode(inData)
    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

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    What do you mean by "not working correctly"?

    What errors does it throw?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Dec 2003
    Location
    Italy
    Posts
    250

    Problems coverting TO Base 64 from ASP

    Hello Hack,
    No errors thrown.
    The thing is this function does not converts the data correctly to Base64 in Windows 2003.
    What I'm getting is something like this:

    Pz8/Pz9BPz8/Pz8/Pz9jPwU/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pyc/Pz8/Pz8/Pz8/Pz8/ Pz8/Pz8/uz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/P68/Pz8/Pz8/Pz8/ Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz9jYQU/jT8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/ Pz8/eD8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/YUE/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/ Pz8/Pz8/Pz8/P1Q/Pz8/Pz8/Pz8/Pz9UPz8/Pz8/Pz8/P1Q/Pz8/Pz8/Pz9DQT9hPz8/Pz8/Pz8/ PyA/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/P68/Pz8/Pz8/YT8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/ Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8

    IT'S NOT THE FULL STRING BECAUSE IT'S TOO LONG, BUT IT'S ALWAYS TE SABE SEQUENCE UNTIL THE END THAT IS CLOSED WITH AN EQUAL (=)

    Instead of the correct converted data.
    But If I convert it with ASP.NET I'm getting the converted data correctly in base64.

    The instructions I'm usigng to convert my data in B64 in .net are:

    Dim strBytes() As Byte = System.Text.Encoding.Default.GetBytes(myData)
    Dim serie As String = System.Convert.ToBase64String(strBytes)

    Maybe do you have a function in VBScript I could use to convert data into base64 the same way I can do it with ASP.Net + VB.Net ?

Similar Threads

  1. sudden problems with asp page
    By KF in forum ASP.NET
    Replies: 3
    Last Post: 03-07-2002, 05:37 PM
  2. ServerSide ASP problems.. Help me please!
    By Joshua Cloud in forum ASP.NET
    Replies: 11
    Last Post: 03-07-2001, 04:29 PM
  3. working on ASP as a beginner!
    By sahar in forum ASP.NET
    Replies: 2
    Last Post: 12-10-2000, 06:18 PM
  4. XMLHTTP problems
    By Bon in forum XML
    Replies: 1
    Last Post: 09-22-2000, 04:34 PM
  5. Multi-page ASP Transactions
    By Dave Kraft in forum ASP.NET
    Replies: 4
    Last Post: 06-05-2000, 05:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center