The gnu base64
util has no option to handle the URL and Filename Safe Alphabet version
(RFC 4648 / section 5) and basenc
(was introduce in coreutils v8.31) is not installed on all hosts.
So just for training, I writed this wrapper in bash!
This script is a wrapper that:
- in encoding process:
- encode with the gnu base64 util
- translate the base64 gnu encoding result to base64url
- in decoding processus:
- translate the base64url encoding to a standard base64
- decode with the gnu base64 util
All the standard options can be set but:
⚠️ the-d
option must be the first argument (if it is used)⚠️ the-i
option must be the second argument (if it is used)
01.txt
MDEydHM_YQ
02.txt
012ts>a
03.txt
MDEy#
dHM_YQ!
$ ./test_base64url
option input expected output test
123456 MTIzNDU2 MTIzNDU2 ok
1234567 MTIzNDU2Nw MTIzNDU2Nw ok
12345678 MTIzNDU2Nzg MTIzNDU2Nzg ok
012ts?a MDEydHM_YQ MDEydHM_YQ ok
012ts>a MDEydHM-YQ MDEydHM-YQ ok
-d MTIzNDU2 123456 123456 ok
-d MTIzNDU2Nw 1234567 1234567 ok
-d MTIzNDU2Nzg 12345678 12345678 ok
-d MDEydHM_YQ 012ts?a 012ts?a ok
-d MDEydHM-YQ 012ts>a 012ts>a ok
-d 01.txt 012ts?a 012ts?a ok
02.txt MDEydHM-YQ MDEydHM-YQ ok
-d -i 03.txt 012ts?a 012ts?a ok
✔️ All test cases are okay!