Restored from previous forum. Originally posted by PB.
Can someone please post an example of how to use the Cipher library
to Base64 encode a binary file into text? I can't figure it out.
Base64 encoding?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
Hi, this works for me.
*Note : I'm using PB3.30 cipher library, but base64 encoding should work ok in PB 3.40 also, i think.
Hi, this works for me.
*Note : I'm using PB3.30 cipher library, but base64 encoding should work ok in PB 3.40 also, i think.
Code: Select all
file.s = OpenFileRequester("Select file", ".\", "*.*|*.*",0)
If file = ""
End
EndIf
If ReadFile(0, file)
inbufferlength.l = Lof()
If AllocateMemory(0, inbufferlength)
outbufferlength.l = inbufferlength + inbufferlength/3 + 2
Debug "outbuff= "+Str(outbufferlength)+", inbuff= "+Str(inbufferlength)
If AllocateMemory(1, outbufferlength, 0)
ReadData(UseMemory(0), inbufferlength)
Base64Encoder(UseMemory(0), inbufferlength, UseMemory(1), outbufferlength)
If CreateFile(1, "encodedfile.txt")
WriteString(PeekS(UseMemory(1)))
CloseFile(1)
Else
Debug "Failed to create file"
EndIf
FreeMemory(1)
Else
Debug "Memory allocation failed (1)"
EndIf
FreeMemory(0)
Else
Debug "Memory allocation failed (0)."
EndIf
CloseFile(0)
Else
Debug "failed to read file"
EndIf
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> this works for me.
Thanks Pupil... it also works fine for me with v3.40.
Do you know any way to attach the Base64'ed file to an e-mail?
Perhaps to merge it with my MailSend procedure found here:
http://www.curvesoftware.co.uk/purebasi ... IC_ID=2049
(As you can tell, I'm trying to send e-mails with attachments).
> this works for me.
Thanks Pupil... it also works fine for me with v3.40.
Do you know any way to attach the Base64'ed file to an e-mail?
Perhaps to merge it with my MailSend procedure found here:
http://www.curvesoftware.co.uk/purebasi ... IC_ID=2049
(As you can tell, I'm trying to send e-mails with attachments).
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
I think you must check out some of the rfc documents to get proper info on this issue, can't really tell which document to read. I think fweil did a nice little rfc browser program quite a while ago, that program might help you in finding the proper document.
You can also check out the message source of mail with attachments that you have received, they might reveal some interesting clues.
I think you must check out some of the rfc documents to get proper info on this issue, can't really tell which document to read. I think fweil did a nice little rfc browser program quite a while ago, that program might help you in finding the proper document.
You can also check out the message source of mail with attachments that you have received, they might reveal some interesting clues.