Solved

Need MIME or Base64 encoding VB implementation

Posted on 1999-01-07
10
570 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 50 total points
ID: 1454619
Thanks,

Pete
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA filters 2 81
how to know if my Checkbox is True in VB6.0? 9 69
Zip Folders Using Chilkat Routines 1 86
Outlook Macro to delete emails not meeting keywords 56 113
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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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