Solved

Downgrade FromBase64String from vb.net to vb6

Posted on 2010-09-02
4
1,285 Views
Last Modified: 2012-05-10
      I have a .Net example application that uses FromBase64String which I need to convert one function from and place in my legacy VB6 application, but I have been unable to find equivenent code.  The function accepts strdata as a string, decodes it from base64 and saves it as a bmp file.  Can anyone tell me how to accomplish this in VB6????

This is the whole code of the function.
       
    Private Sub SaveImageData(ByVal sigdata As String)

        Dim b() As Byte = Convert.FromBase64String(strdata)
        Dim fs As IO.FileStream = IO.File.Create("C:\temp.bmp")
        fs.Write(b, 0, b.Length)
        fs.Close()

0
Comment
Question by:FNDAdmin
4 Comments
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
ID: 33588024
The following link should be helpful:

http://www.nonhostile.com/howto-encode-decode-base64-vb6.asp

0
 
LVL 12

Expert Comment

by:GMGenius
ID: 33588044
Here is a link to a sample class you could use
Use the DecodeToByteArray and save the byte array to file
http://www.mcmillan.org.nz/paradoxes/code/base64.html
I hope this helps
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 33588276
You can also use the cryptography API

Option Explicit

'egl1044

'WinXP or later

Private Const CRYPT_STRING_BASE64 As Long = &H1&



Private Declare Function CryptStringToBinaryW Lib "Crypt32.dll" ( _

  ByVal pszString As Long, _

  ByVal cchString As Long, _

  ByVal dwFlags As Long, _

  ByVal pbBinary As Long, _

  ByRef pcbBinary As Long, _

  ByVal pdwSkip As Long, _

  ByVal pdwFlags As Long) As Long



Public Function FromBase64String(ByVal data As String) As Byte()

  Dim Buffer() As Byte

  Dim dwBinaryBytes As Long

  dwBinaryBytes = LenB(data)

  ReDim Buffer(dwBinaryBytes - 1) As Byte

  If CryptStringToBinaryW(StrPtr(data), LenB(data), CRYPT_STRING_BASE64, _

    VarPtr(Buffer(0)), dwBinaryBytes, 0, 0) Then

    ReDim Preserve Buffer(dwBinaryBytes - 1) As Byte

    FromBase64String = Buffer

  End If

  Erase Buffer

End Function



Private Sub Form_Load()

  Dim image() As Byte

  image() = FromBase64String("c3VyZS4=") 'sure.

  Debug.Print StrConv(image, vbUnicode)

End Sub

Open in new window

0
 

Author Closing Comment

by:FNDAdmin
ID: 33596519
Thanks to everyone that posted solutions.  They all look like they shoudl work, but for some reason all three gave me a different decoded output, and only the XML was correct in my situation, I'm not exactly sure why.  Worked great though, thank you.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
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…

896 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

17 Experts available now in Live!

Get 1:1 Help Now