1base64(n) Text encoding & decoding binary data base64(n)
2
3
4
5______________________________________________________________________________
6
8 base64 - base64-encode/decode binary data
9
11 package require Tcl 8
12
13 package require base64 ?2.3.2?
14
15 ::base64::encode ?-maxlen maxlen? ?-wrapchar wrapchar? string
16
17 ::base64::decode string
18
19_________________________________________________________________
20
22 This package provides procedures to encode binary data into base64 and
23 back.
24
25 ::base64::encode ?-maxlen maxlen? ?-wrapchar wrapchar? string
26 Base64 encodes the given binary string and returns the encoded
27 result. Inserts the character wrapchar every maxlen characters
28 of output. wrapchar defaults to newline. maxlen defaults to 60.
29
30 Note well: If your string is not simple ascii you should fix the
31 string encoding before doing base64 encoding. See the examples.
32
33 ::base64::decode string
34 Base64 decodes the given string and returns the binary data.
35 The decoder ignores whitespace in the string.
36
38 % base64::encode "Hello, world"
39 SGVsbG8sIHdvcmxk
40
41
42 % base64::encode [string repeat xyz 20]
43 eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6
44 eHl6eHl6eHl6
45 % base64::encode -wrapchar "" [string repeat xyz 20]
46 eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6
47
48
49 # NOTE: base64 encodes BINARY strings.
50 % set chemical [encoding convertto utf-8 "C\u2088H\u2081\u2080N\u2084O\u2082"]
51 % set encoded [base64::encode $chemical]
52 Q+KCiEjigoHigoBO4oKET+KCgg==
53 % set caffeine [encoding convertfrom utf-8 [base64::decode $encoded]]
54
55
57 base64, encoding
58
60 Copyright (c) 2000, Eric Melski
61 Copyright (c) 2001, Miguel Sofer
62
63
64
65
66base64 2.3.2 base64(n)