diff --git a/README.md b/README.md index 9d849b1..2d27f20 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1426 TILs and counting..._ +_1427 TILs and counting..._ --- @@ -1376,6 +1376,7 @@ _1426 TILs and counting..._ - [Fix Unlinked Node Binaries With asdf](unix/fix-unlinked-node-binaries-with-asdf.md) - [Forward Multiple Ports Over SSH](unix/forward-multiple-ports-over-ssh.md) - [Generate A SAML Key And Certificate Pair](unix/generate-a-saml-key-and-certificate-pair.md) +- [Generate Base64 Encoding Without Newlines](unix/generate-base64-encoding-without-newlines.md) - [Generate Random 20-Character Hex String](unix/generate-random-20-character-hex-string.md) - [Get A List Of Locales On Your System](unix/get-a-list-of-locales-on-your-system.md) - [Get Matching Filenames As Output From Grep](unix/get-matching-filenames-as-output-from-grep.md) diff --git a/unix/generate-base64-encoding-without-newlines.md b/unix/generate-base64-encoding-without-newlines.md new file mode 100644 index 0000000..e666a54 --- /dev/null +++ b/unix/generate-base64-encoding-without-newlines.md @@ -0,0 +1,25 @@ +# Generate Base64 Encoding Without Newlines + +There are a variety of tools that can generate a Base64 encoding of given text. +Most of them that I've encountered have a number of characters at which they +introduce a newline character. Here is `openssl` as an example: + +```bash +❯ echo "here is a long bit of text to base64 encode with openssl" | openssl base64 +aGVyZSBpcyBhIGxvbmcgYml0IG9mIHRleHQgdG8gYmFzZTY0IGVuY29kZSB3aXRo +IG9wZW5zc2wK +``` + +[The theory I've seen](https://superuser.com/a/1225139) is that this is to +accommodate 80-character terminal screens when chunks of encoding were included +in emails. + +With the `openssl base64` command, there is not an option to exclude the +newlines, but we can pipe it through `tr` to remove them. + +```bash +❯ echo "here is a long bit of text to base64 encode with openssl" | \ + openssl base64 | \ + tr -d '\n' +aGVyZSBpcyBhIGxvbmcgYml0IG9mIHRleHQgdG8gYmFzZTY0IGVuY29kZSB3aXRoIG9wZW5zc2wK +```