VB6 saving file to make .pdf file

I am receiving a Base64 file (which is actually a .pdf file).  I am successfully decoding the Base64 ascii file that I am receiving.  

 However, when I go to save the file, it doesn't seem to open in .pdf (recognisizes it as a damaged file).  I am trying to save the file in VB6 as a binary file.

The way I am verifying this is that I take the .pdf file (the original from which the person used a Base64 to encode it) and then use WORDPAD to view it.  I see the familiar %PDF-1.2 etc in the file.  this is the same starting string that I get when I decode the Base64 string in VB6.  I even matched every line from the .pdf vs the file that I saved in VB6.  The file size is slightly off (the VB6 is larger), don't know if there is a header of some sort that I am missing for Adobe Reader to recognize the file I save in VB6.

I used a free online Base64 decoder (www.motobit.com/util/base64-decoder-encoder.asp) and cut/paste the string that is sent to me, and then used the option to save the file as a binary file.  when I renamed the extension of the saved binary file to .pdf, it opened perfectly in Adobe reader.

Any ideas on what I am doing wrong?  My guess is that I am not using VB6 to save to binary correctly.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need to show us your code. It is obviously a bug somewhere
ADEZOYSA1Author Commented:
find below the coding that I have in place.  I am using Chilkat's activex to do the decoding.

Private Sub Command2_Click()
    Dim Decrypt As New ChilkatCrypt2
    Dim Line_From_File As String
    Dim Decrypt_Data As String
    'open the file
    Open "c:\originals\base64\raw data\test.txt" For Input As 1
    Open "c:\originals\base64\raw data\test1.pdf" For Output As 2
    Dim success As Long
    success = Decrypt.UnlockComponent("?????")
    If (success <> 1) Then
        Text1.Text = Text1.Text & crypt.LastErrorText & vbCrLf
        Exit Sub
    End If
    'get the base64 file
    Line Input #1, Line_From_File
    Decrypt.CryptAlgorithm = "none"
    Decrypt.EncodingMode = "base64"
    Decrypt_Data = Decrypt.DecryptStringENC(Line_From_File)
    'write to file
    Print #2, Decrypt_Data
    Close #1
    Close #2

    MsgBox ("completed")

End Sub
I have checked the Chilkat's documentation. I believe in your case you need to use the DecryptBytesENC() method that returns the binary Byte array.
Also, you need to open the pdf file with the "For Binary Access Write" option, like this:
 Open "c:\originals\base64\raw data\test1.pdf" For For Binary Access Write As 2

Open in new window

When you write your data from the byte array returned by the DecryptBytesENC function you will need to write the bytes one-by-one in a loop to make sure that all the bytes written correctly

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ADEZOYSA1Author Commented:
This worked!  Thanks.

I used the strcovr function to write the byte array and it worked like a charm.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.