Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need MIME or Base64 encoding VB implementation

Posted on 1999-01-07
10
Medium Priority
?
584 Views
Last Modified: 2008-03-17
I'm looking for a VB implementation of base64 encoding of a string. So no dll's or other modules and no delphi or c code.

Comments only please. I'll award the points when the correct answer has been given.
0
Comment
Question by:Mirkwood
10 Comments
 
LVL 2

Expert Comment

by:peterwest
ID: 1454617
Hi there,

Try the following - i've used it in the past and it works fine for me.  I'll post a routine for decoding too if you need it.

THanks

Pete
--------------------


Private Declare Function CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ptrDest As Any, ptrSource As Any, ByVal lenCopy As Long) As Long

Private Sub USAsciiToBase64(bIN() As Byte, b64() As Byte)

   Const TriPadding As Byte = 61 ' =
   Const Base64Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
   Static Base64(0 To 63) As Byte, Initialized As Boolean
   Dim TriBuf(0 To 3) As Byte, b As Byte, TriBits&
   Dim Trips&, Xtras&, bInLen&, bInPtr&, b64Ptr&

   If Not Initialized Then
      Initialized = True
      For b = 0 To 25
         Base64(b) = b + 65
         Base64(b + 26) = b + 97
      Next
      For b = 52 To 61
         Base64(b) = b - 4
      Next
      Base64(62) = 43
      Base64(63) = 47
   End If
   bInLen = UBound(bIN) - LBound(bIN) + 1
   Trips = bInLen \ 3
   Xtras = bInLen Mod 3
   ReDim b64(0 To IIf(Xtras, Trips + 1, Trips) * 4 + 1) '+1 for vbCrLf
   For bInPtr = 0 To Trips * 3 - 1 Step 3
      TriBuf(2) = bIN(bInPtr)
      TriBuf(1) = bIN(bInPtr + 1)
      TriBuf(0) = bIN(bInPtr + 2)
      CopyMemory TriBits, TriBuf(0), 3
      b64(b64Ptr) = Base64(TriBits \ &H40000)
      b64(b64Ptr + 1) = Base64((TriBits \ &H1000&) And &H3F&)
      b64(b64Ptr + 2) = Base64((TriBits \ &H40&) And &H3F&)
      b64(b64Ptr + 3) = Base64(TriBits And &H3F&)
      b64Ptr = b64Ptr + 4
   Next
   If Xtras > 0 Then
      TriBuf(0) = 0 'TriPadding
      TriBuf(2) = bIN(bInPtr)
      If Xtras > 1 Then
         TriBuf(1) = bIN(bInPtr + 1)
      Else
         TriBuf(1) = 0 'TriPadding
      End If
      CopyMemory TriBits, TriBuf(0), 3
      b64(b64Ptr) = Base64(TriBits \ &H40000)
      b64(b64Ptr + 1) = Base64((TriBits \ &H1000&) And &H3F&)
      b64(b64Ptr + 2) = IIf(Xtras = 1, TriPadding, Base64((TriBits \ &H40&) And &H3F&))
      b64(b64Ptr + 3) = TriPadding 'IIf(Xtras > 1, TriPadding, Base64(TriBits And &H3F&))
      b64Ptr = b64Ptr + 4
   End If
   b64(b64Ptr) = 13 'vbCr
   b64(b64Ptr + 1) = 10 'vbLf

End Sub

0
 
LVL 13

Author Comment

by:Mirkwood
ID: 1454618
With some byte & string conversion everything seems to be working OK. Please answer the question PeterWest to receive your points.
0
 
LVL 2

Accepted Solution

by:
peterwest earned 200 total points
ID: 1454619
Thanks,

Pete
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Expert Comment

by:mark2150
ID: 1454620
Hey Mirkwood!

You can download an entire MIME decoder program from my website - all source included!

www.cyberchute.com/rvbus/madmark

M

0
 

Expert Comment

by:jknickelbein
ID: 1454621
PeterWest,
Could you please post that decoding code for me?  It would be really helpful.
0
 
LVL 2

Expert Comment

by:peterwest
ID: 1454622
jknickelbein,

I'll happily post the code you request but not under this question - i'd rather have it in a seperate question so other people browsing the PAQ's can find it.  Point's aren't an issue for me - i'm certainly not point hungry - so if you post a question, just assign it 5 points or something, and i'll happily post the code.

Thanks

Pete

0
 
LVL 4

Expert Comment

by:idcanada
ID: 1454623
peterwest,
Could you please notify me when you do post this code.

Thanks.
0
 
LVL 2

Expert Comment

by:peterwest
ID: 1454624
idcanada,

How do you want me to notify you???

Pete

0
 
LVL 4

Expert Comment

by:idcanada
ID: 1454625
I thought this was a good notification :)
0
 

Expert Comment

by:drjoeross
ID: 7550885
I would be very interested in seeing the code for the Mime decoder. I could not currently locate it on this site.
Thanks,
Joe
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question