Base64 package guide
Use Base64 to encode and decode text or file bytes and to generate time-based one-time passwords from a base32 secret.
Version 2.17.1. Installed versions can differ. Examples are illustrative and not tested.
Prerequisites
The actions run on the Device and need no other application or session. result → x means: save the output in variable x. Fields not marked required are optional and use the default in the table when empty. Invalid Base64, a file you cannot read or a path you cannot write fails the step.
- Decoding to a file overwrites that file.
- A relative path starts at the working folder of the Run. Absolute paths work. Environment variables and home-folder shortcuts are not expanded. File actions hold the full file in memory.
- Text actions use UTF-8. Use the file actions for images and other binary files: they keep the original bytes.
- Base64 here uses
+,/and=at the end where needed. The decoders ignore spaces and line breaks. Remove adata:...;base64,prefix first, and change-and_to+and/. - Base64 is encoding, not encryption.
- TOTP: put the base32 secret from the service in a Credential (password field). Use the algorithm, digits and period of that service. The Device clock must be correct.
Actions
Base64 Decode (base64Decode)
Decode Base64 into a file. Missing parent folders are created.
Inputs
| ID | Editor field | Type; default; requirement | Use |
|---|---|---|---|
str | Base64 string to be decoded | Stringdefault ""required | Base64 text or a String variable. |
str | File path to be saved | Stringdefault ""required | File to write. The extension does not change the bytes. |
Outputs
| ID | Type | Meaning |
|---|---|---|
result | String | Full path of the written file. |
Example
Set strBase64=c2FsdmU= and strTargetPath=samples/decoded.txt. result → writtenPath.
Expected result
The file contains salve. writtenPath is the full path to samples/decoded.txt. If the step fails, parent folders may already exist.
Decode base64 (base64DecodeString)
Decode Base64 into UTF-8 text. Use Base64 Decode for binary content.
Inputs
| ID | Editor field | Type; default; requirement | Use |
|---|---|---|---|
source | Base64 encoded string | Stringdefault ""required | Base64 text. |
Outputs
| ID | Type | Meaning |
|---|---|---|
result | String | Decoded UTF-8 text. |
Example
Set sourceString=c2FsdmU=. result → decoded.
Expected result
decoded is salve. If the bytes are not UTF-8 text, you get replacement characters (�) and no error: use Base64 Decode to a file instead.
Base64 Encode (base64Encode)
Encode all bytes of a file as Base64, with no text conversion.
Inputs
| ID | Editor field | Type; default; requirement | Use |
|---|---|---|---|
str | File to be encoded | Stringdefault ""required | File to read. |
Outputs
| ID | Type | Meaning |
|---|---|---|
result | String | Base64 of all file bytes, with no line breaks. |
Example
Prepare samples/input.txt that contains only salve, with no line break at the end and no byte order mark. Set strFilePath=samples/input.txt. result → encoded.
Expected result
encoded is c2FsdmU=. Every byte counts, so a line break or byte order mark changes it. An empty file gives "".
Encode base64 (base64EncodeString)
Encode text as UTF-8, then as Base64. A path typed as text is not read as a file.
Inputs
| ID | Editor field | Type; default; requirement | Use |
|---|---|---|---|
source | Source string | Stringdefault ""required | Typed text or a String variable. UTF-8, with no byte order mark. |
Outputs
| ID | Type | Meaning |
|---|---|---|
result | String | Base64 of the UTF-8 text, with no line breaks. |
Example
Set sourceString=salve. result → encoded.
Expected result
encoded is c2FsdmU=. Case, spaces and line breaks change it. Decode base64 gives back the original text.
Generate TOTP (base64GenerateTotp)
Make the current and the next one-time code from a base32 secret. It does not enroll an account or send a code.
Inputs
| ID | Editor field | Type; default; requirement | Use |
|---|---|---|---|
secret | Secret key | Credentialdefault requiredno default (user name and password start empty) | Credential whose password is the base32 secret (if empty, the user name is used). A String variable does not work. Case, spaces, hyphens and = do not matter. Not Base64, not a full enrollment link. |
algorithm | Algorithm | Totpdefault SHA1 | SHA1, SHA256 or SHA512, as the service uses. |
code | Code digits | Numberdefault 6 | Whole code length, 6 to 8. |
time | Time step | Numberdefault 30 | Period in whole seconds, as the service uses. Usually 30. |
Outputs
| ID | Type | Meaning |
|---|---|---|
current | String | Code for the current period, leading zeros kept. |
next | String | Code for the next period. The service may refuse it before that period starts. |
seconds | Number | Whole seconds until the current period ends, 1 to time, read once when the step runs. |
Example
For a test only, prepare Credential variable testTotp with an empty user name and the public test secret GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ in its password field. This secret opens no account. Set secret=$testTotp$, algorithm=SHA1, codeDigits=6 and timeStep=30. Save the outputs in String variables current and next, and Number variable remaining.
Expected result
current and next have six digits each, with leading zeros kept. The codes depend on the Device clock. current is for this 30-second period, next for the one after. remaining is from 1 to 30. Digits outside 6 to 8, a period of 0 or less, an empty secret, or a character that is not base32 fails the step.