b64 - Base64 module

Module Description

The b64 module implements the encoding to and decoding from base64.

Module Words

Base64 conversion words

b64-encode ( c-addr1 u1 str -- c-addr2 u2 )
Encode the string c-addr u with str, resulting in c-addr2 u2 in str
b64-decode ( c-addr1 u1 str -- c-addr2 u2 )
Decode the string c-addr1 u1 using str, resulting in c-addr2 u2 in str, throws exp-invalid-data for characters out of range

Examples

include ffl/b64.fs


\ Create a string in the dictionary for storing the encoded characters

str-create inbase64

\ Encode the string: The quick brown fox jumps over the lazy dog

s" The quick brown fox jumps over the lazy dog" inbase64 b64-encode

\ Print the result

.( Base64 encoding of 'The quick brown fox jumps over the lazy dog' is: ) type cr

\ The result is also stored in inbase64

.( inbase64 contents: ) inbase64 str-get type cr


\ Create a string on the heap for storing the decoded characters

str-new value frombase64

\ Decode the encoded string of The quick brown fox jumps over the lazy dog

s" VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==" frombase64 b64-decode

.( Base64 decoding of 'VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==' is: ) type cr

\ The result is also stored in frombase64

.( frombase64 contents: ) frombase64 str-get type cr

\ Free the string from the heap

frombase64 str-free

generated 03-Jun-2010 by ofcfrth-0.10.0