Tech » Base64
This library is only roughly tested.
Please let me know, if you find bugs or improvements.
Base 64 encoder/decoder for Lotus Script
This an implementation of Base64 as described in rfc4648
(The Base16, Base32, and Base64 Data Encodings) for the Lotus Notes
environment.
Base64 is an algorithm to encode binary data into a ascii text representation.
Common applications are
This library makes use of NotesStreams and NotesMIMEEntity that came
with Notes 6. It therefore is really fast (several MBytes per second).
For example it should be a lot faster than the popular implementation
by Julian Robichaux on http://www.nsftools.com.
Usage
- Save and unzip the code to a text file (libBase64.lss)
- Use Domino Designer to create a new empty Lotus Script library 'libBase64'
- Import libBase64.lss and save the lib
- Now you can include the library (
Use "libBase64")
and use it:
Dim b64 As New CBase64()
Call b64.encode (..)
See 'Samples' below for more.
Download
Download libBase64.lss (9kB)
Download libBase64.zip (3kB)
Related links
MD5 encoder
Terms of Use
This code may be used freely, as long as you accept the following terms
of use:
- NO WARRANTY of any kind is given.
Use this code it a your own risk OR DON'T USE IT AT ALL.
Also, I may not be able to support or maintain it in the future.
- The comment header must be left intact.
If you make changes, add an additional comment describing it.
Even better: if you find bugs or improvements please let me know, so
we can share it.
Samples
Encode a string to base64
Dim b64 As New CBase64()
Print b64.encodeString ("foobar")
Encode a binary file to a base64 encoded file
Dim b64 As New CBase64()
Call b64.encodeFileToFile (fspecInput, fspecOutput)
The result file will have line breaks at column 76. If this is not desired,
than it can be suppressed. This will be a bit slower however:
Dim b64 As New CBase64()
b64.bMimeModeEncoding = False
Call b64.encodeFileToFile (fspecInput, fspecOutput)
Decode a base64 encoded file to a (probably binary) file
Dim b64 As New CBase64()
Call b64.decodeFileToFile (fspecInput, fspecOutput)
Description
Class CBase64
Public bMimeModeEncoding As Boolean
Set bMimeModeEncoding to False, if the encoding result should NOT contain line feeds at column 76
This is SLOWER, beacuse the LF is removed in a seperate scan afterwards (default is True)
Function encode (nsIn As NotesStream) As String
Function encodeString (strIn As String) As String
Function encodeFile (Byval fspecIn As String) As String
Function encodeFileToFile (Byval fspecIn As String, Byval fspecOut As String) As Boolean
Function decode (nsIn As NotesStream) As NotesStream
Function decodeString (strIn As String) As NotesStream
Function decodeStringToString (strIn As String) As String
Use this function only, if you are sure that the encoded content is not binary.
Function decodeFile (Byval fspecIn As String) As NotesStream
Function decodeFileToFile (Byval fspecIn As String, Byval fspecOut As String) As Boolean
Function isValidBase64 (s As String) As Boolean
Check if s is a valid b64 encoding.
Sub removeWhitespace (s As String)
Remove all CR, LF, tabs, and spaces from s.
End Class
|