class Base64 extends Object
Converts between binary data and Base64 text. Both methods are called on the class itself.
The class is exported by the KS module:
#Import "Ks" { Base64 }
Encodes binary data as Base64 text.
Text := Base64.Encode(Value , Encoding := "UTF-8")
Type: Buffer, StringBuffer or String
The data to encode. A Buffer is encoded exactly as it stands, so Encoding does not apply to it. A StringBuffer is encoded as its text, the same as the equivalent string.
Type: String
The encoding a string or StringBuffer Value is converted to bytes with, named as for FileEncoding. If omitted, it defaults to UTF-8. A name which cannot be resolved throws a ValueError.
Type: String
Returns the Base64 text.
Decodes Base64 text to bytes.
Data := Base64.Decode(Text)
Type: String
The Base64 text to decode.
Type: Buffer
Returns a Buffer holding the decoded bytes.
Text which is not well-formed Base64 throws a ValueError.
#Import "Ks" { Base64 }
Base64.Encode("Hello, world!") ; "SGVsbG8sIHdvcmxkIQ=="
StrGet(Base64.Decode("SGVsbG8="), "UTF-8") ; "Hello"
Base64.Encode("abc", "UTF-16") ; "YQBiAGMA"
Sends HTTP Basic authentication credentials:
#Import "Ks" { Http, Base64 }
Http.Get(Url, {Headers: Map("Authorization", "Basic " Base64.Encode(User ":" Password))})