Base64
Moderators: Susan Smith, admin, Gabriel
-
- Posts: 292
- Joined: Fri Jun 19, 2009 9:01 am
- Location: Lawrence, Kansas
- Contact:
Base64
Has anybody come up with a means in BR to encode and decode base64 data? Receiving some data from a website that has been encoded in base64 so I need to decode it. Wanted to check before I wrote my own.
Steve Koger
Computer Specialist
SEKESC-MACS Division
Computer Specialist
SEKESC-MACS Division
Re: Base64
It looks like Windows has a command line tool that might meet your needs:
http://stackoverflow.com/questions/1694 ... 4-in-batch
To encode a file:
certutil -encode inputFileName encodedOutputFileName
To decode a file:
certutil -decode encodedInputFileName decodedOutputFileName
There are a number of available verbs and options available to CERTUTIL.
To get a list of nearly all available verbs:
certutil -?
To get help on a particular verb (-encode for example):
certutil -encode -?
To get complete help for nearly all verbs:
certutil -v -?
Mysteriously, the -encodehex verb is not listed with certutil -? or certutil -v -?. But it is described using certutil -encodehex -?
http://stackoverflow.com/questions/1694 ... 4-in-batch
To encode a file:
certutil -encode inputFileName encodedOutputFileName
To decode a file:
certutil -decode encodedInputFileName decodedOutputFileName
There are a number of available verbs and options available to CERTUTIL.
To get a list of nearly all available verbs:
certutil -?
To get help on a particular verb (-encode for example):
certutil -encode -?
To get complete help for nearly all verbs:
certutil -v -?
Mysteriously, the -encodehex verb is not listed with certutil -? or certutil -v -?. But it is described using certutil -encodehex -?
-
- Posts: 292
- Joined: Fri Jun 19, 2009 9:01 am
- Location: Lawrence, Kansas
- Contact:
Re: Base64
Perfect! Was not making much progress coding my own!
Thanks Luis!
Thanks Luis!
Steve Koger
Computer Specialist
SEKESC-MACS Division
Computer Specialist
SEKESC-MACS Division
-
- Posts: 292
- Joined: Fri Jun 19, 2009 9:01 am
- Location: Lawrence, Kansas
- Contact:
Re: Base64
Updating everyone on the status of my request for Base64 Encoding and Decoding.
Luis suggested a utility on Windows that I could use called certutil. I researched and found in fact that I could. The syntax is as follows:
This would decode a file containing data that had been encoded base64. This works on windows.
On the Mac I found a similar utility:
Both utilities seem to work just fine. But I was not satisfied with having to make a shell call anytime I wanted to encode or decode a dataset. So I started doing some research and found this Wikipedia page that described what was required to roll your own. So that I did.
https://en.wikipedia.org/wiki/Base64
I created a library that contains FN_ENCODEDBASE64(CONTENT$) & FN_DECODEBASE64(CONTENT$) Both functions use a pointer to CONTENT$ so the result is returned in place of the what was sent. CONTENT$ is limited to 1,200,000 characters and you will need to make sure your workstack can accommodate a string of that size. It can handle any characters is the ASCII character set from 0 to 255.
Just load the library in your calling program Then use one of the functions. Here is an example of Encoding some simple text:
Your output from this should be: TWFu
This is one of the examples on the Wikipedia Page. You can read through that to see how the encoding is done.
Please test in your environment and don't hesitate to give me feedback if you find any issues!
I have attached the source code to this post. You will need to rename the extension to .wbs or .brs to use
Luis suggested a utility on Windows that I could use called certutil. I researched and found in fact that I could. The syntax is as follows:
Code: Select all
00450 If WBPLATFORM$="WINDOWS" Then Execute "sys -m certutil -decode encoded.fil decoded.fil"
On the Mac I found a similar utility:
Code: Select all
00470 ! If WBPLATFORM$="MAC" Then Execute "sys -m openssl -d -in encoded.fil -out decoded.fil"
https://en.wikipedia.org/wiki/Base64
I created a library that contains FN_ENCODEDBASE64(CONTENT$) & FN_DECODEBASE64(CONTENT$) Both functions use a pointer to CONTENT$ so the result is returned in place of the what was sent. CONTENT$ is limited to 1,200,000 characters and you will need to make sure your workstack can accommodate a string of that size. It can handle any characters is the ASCII character set from 0 to 255.
Just load the library in your calling program Then use one of the functions. Here is an example of Encoding some simple text:
Code: Select all
00010 Library Release,"\macprg\base64_l": FN_ENCODEBASE64,FN_DECODEBASE64
00030 DIM CT$*1200000
00050 LET CT$="Man"
00070 LET FN_ENCODEBASE64(CT$)
00090 PRINT CT$
This is one of the examples on the Wikipedia Page. You can read through that to see how the encoding is done.
Please test in your environment and don't hesitate to give me feedback if you find any issues!
I have attached the source code to this post. You will need to rename the extension to .wbs or .brs to use
- Attachments
-
- base64_l.txt
- Rename extension to .wbs or .brs
- (7.13 KiB) Downloaded 826 times
Steve Koger
Computer Specialist
SEKESC-MACS Division
Computer Specialist
SEKESC-MACS Division