-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64
More file actions
36 lines (29 loc) · 678 Bytes
/
Copy pathbase64
File metadata and controls
36 lines (29 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Use below code as a tool in linux terminal to decode or encode files, text, etc., in base64
EXAMPLE USAGE:
Encode:
encode sample.txt > encoded-sample.txt
Decode:
decode encoded-sample.txt
Encode (code for bash file):
#!/bin/bash
if [ -f "$1" ]; then
base64 "$1"
elif [ -n "$1" ]; then
echo -n "$1" | base64
else
echo "that is a NOGO" >&2
exit 1
fi
Decode (code for bash file):
#!/bin/bash
# Check if the input is a file
if [ -f "$1" ]; then
# Decode the Base64 contents of the file
base64 --decode "$1"
elif [ -n "$1" ]; then
# Decode the provided Base64 string
echo -n "$1" | base64 --decode
else
echo "No input provided" >&2
exit 1
fi