Solved

Need MIME or Base64 encoding VB implementation

Posted on 1999-01-07
10
558 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
Comment Utility
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
Comment Utility
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 50 total points
Comment Utility
Thanks,

Pete
0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
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
Comment Utility
PeterWest,
Could you please post that decoding code for me?  It would be really helpful.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 2

Expert Comment

by:peterwest
Comment Utility
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
Comment Utility
peterwest,
Could you please notify me when you do post this code.

Thanks.
0
 
LVL 2

Expert Comment

by:peterwest
Comment Utility
idcanada,

How do you want me to notify you???

Pete

0
 
LVL 4

Expert Comment

by:idcanada
Comment Utility
I thought this was a good notification :)
0
 

Expert Comment

by:drjoeross
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now