Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
26
votes
3
answers
62380
views
base64 -d decodes, but says invalid input
Does anybody know why this is happening and how to fix it? ``` me@box:~$ echo "eyJmb28iOiJiYXIiLCJiYXoiOiJiYXQifQ" | base64 -di {"foo":"bar","baz":"bat"}base64: invalid input ```
Does anybody know why this is happening and how to fix it?
me@box:~$ echo "eyJmb28iOiJiYXIiLCJiYXoiOiJiYXQifQ" | base64 -di
{"foo":"bar","baz":"bat"}base64: invalid input
shwoseph
(435 rep)
Jan 28, 2021, 05:45 PM
• Last activity: Jul 27, 2025, 02:01 PM
1
votes
1
answers
2285
views
Remove newline character after pipe
I want to do Base64 encode with a command echo -en "my_message" | openssl sha1 -hmac "secret_key" | base64 The output string of `openssl` is as expected, but the output of base64 is not as the output from openssl has a new line character. If I run the command echo -en "my_message" | openssl sha1 -hm...
I want to do Base64 encode with a command
echo -en "my_message" | openssl sha1 -hmac "secret_key" | base64
The output string of
openssl
is as expected, but the output of base64 is not as the output from openssl has a new line character. If I run the command
echo -en "my_message" | openssl sha1 -hmac "secret_key" | xargs echo -n | base64
Then the final output is correct.
I wonder if there is a more elegant way for this command
Dino Tw
(111 rep)
Mar 26, 2020, 07:34 AM
• Last activity: Jul 14, 2025, 12:02 PM
0
votes
2
answers
7712
views
Concatenate 2 binary strings in base64 form
I have two BASE64 encoded strings and I would like to get the BASE64 encoding of the binary concatenation of the two string using just the command line. Example: > $ echo -n "\x01\x02" |base64 AQI= > $ echo -n "\x03\x04" |base64 AwQ= > $ echo -n "\x01\x02\x03\x04" |base64 AQIDBA== So the input value...
I have two BASE64 encoded strings and I would like to get the BASE64 encoding of the binary concatenation of the two string using just the command line.
Example:
> $ echo -n "\x01\x02" |base64
AQI=
> $ echo -n "\x03\x04" |base64
AwQ=
> $ echo -n "\x01\x02\x03\x04" |base64
AQIDBA==
So the input values to my problem would be
AQI=
and AwQ=
, the desired output is AQIDBA==
mat
(309 rep)
Jun 8, 2017, 12:17 PM
• Last activity: Aug 20, 2024, 07:04 PM
0
votes
3
answers
3026
views
How to decode base64 text in ldif file in Linux?
I need to decode base64 embedded in ldif (openldap) backups. I found [here][1] a way to join lines starting with a blank. Then, based on [this][2] question about "How to decode base64 text in xml file in Linux?" I want to decode the base64 strings, but I'm not being able to get it to work. My Script...
I need to decode base64 embedded in ldif (openldap) backups.
I found here a way to join lines starting with a blank.
Then, based on this question about "How to decode base64 text in xml file in Linux?" I want to decode the base64 strings, but I'm not being able to get it to work.
My Script is:
#Join lines starting with space
sed -n 'H; ${ x; s/\n//; s/\n //g; p}' "$FILE" > "$FILE_JOINED"
#Decode lines containing base64 (those with double colon)
sed -r 's/(:: )([[:graph:]]+)/\1 '"
grep -oP ':: [[:graph:]]+' "$FILE_JOINED" |cut -c 4- | base64 -d
"'/g' "$FILE_JOINED"
When I execute this, I get the following error:
sed: -e expression #1, char 297: unknown option to `s'
Here I add an example of the "$FILE_JOINED" contents:
dn: olcDatabase={1}mdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcMdbConfig
olcDatabase: {1}mdb
olcDbDirectory: /var/lib/ldap
olcSuffix: dc=proxy,dc=ldap
olcAccess:: b25lIHZhbHVlCg==
olcAccess: {1}to filter=(&(objectClass=securityPrincipal)(!(pwdAccountLockedTime=*))) attrs=userPassword,shadowLastChange by dn="cn=Man1,ou=local,dc=proxy,dc=ldap" write by anonymous auth by self write by * none
olcAccess: {2} to * by * read
olcAddContentAcl: FALSE
olcLastMod: TRUE
olcMaxDerefDepth: 15
olcReadOnly: FALSE
olcRootDN: cn=Man1,ou=local,dc=proxy,dc=ldap
olcRootPW:: dmFsdWUgdHdvCg==
olcSyncUseSubentry: FALSE
olcSyncrepl:: dmFsdWUgdGhyZWUK
olcMirrorMode: TRUE
dn: olcOverlay={0}unique,olcDatabase={1}mdb,cn=config
objectClass: olcOverlayConfig
objectClass: olcUniqueConfig
(NOTE that the second command leaves the double colon (::
) instead of leaving only one. I did it on purpose to be able to easily grep the output. I'll fix that later)
The second command has a grep in it: How does it "select" the correct line to decode in all the file contents?
Here is the result of the grep
command alone:
# grep -oP ':: [[:graph:]]+' x |cut -c 4- | base64 -d
one value
value two
value three
Could anybody please give me any pointers on how to decode the base64 values contained in a ldif file?
elysch
(131 rep)
Aug 30, 2018, 12:55 AM
• Last activity: Jul 2, 2024, 10:10 PM
2
votes
2
answers
11846
views
How to properly encode string based on json file?
I have the following `basic.json` file: ``` { "user": "user", "pass": "password" } ``` I'm trying to encode it in base64 like this: ``` "Basic dXNlcjpwYXNzd29yZA==" ``` I think I'm close: ``` echo Basic $(echo $(cat basic.json | jq '.user'):$(cat basic.json | jq '.pass') | base64) ``` I've used the...
I have the following
basic.json
file:
{
"user": "user",
"pass": "password"
}
I'm trying to encode it in base64 like this:
"Basic dXNlcjpwYXNzd29yZA=="
I think I'm close:
echo Basic $(echo $(cat basic.json | jq '.user'):$(cat basic.json | jq '.pass') | base64)
I've used the [jq access method found here](https://shapeshed.com/jq-json/#how-to-find-a-key-and-value) .
I've used the [base64 method found here](https://linuxhint.com/bash_base64_encode_decode/) .
But the result is wrong:
Basic InVzZXIiOiJwYXNzd29yZCIK
I've tried the -e
flag as mentioned in the article:
echo Basic $(echo $(cat basic.json | jq '.user'):$(cat basic.json | jq '.pass') | base64 -e)
But it throws this error:
> base64: invalid option -- 'e'
Where did I mistake?
Thanks in advance.
---
**My solution**
The command ended this way:
RUN echo "map \"\" \$basicAuth {\n\
\tdefault $(jq '"Basic " + ("\(.user):\(.pass)" | @base64)' basic.json);\n\
}" > basic.conf
And my basic.conf
file finally have the correct basic auth:
map "" $basicAuth {
default "Basic dXNlcjpwYXNzd29yZA==";
}
Thank you all
Washington Guedes
(133 rep)
Jun 1, 2020, 02:01 PM
• Last activity: Jun 3, 2024, 08:27 AM
0
votes
2
answers
669
views
How to base64 encode/decode accents characters
I am trying to base64 encode a string which contains accent characters. echo FILE_DATE.Ç | iconv -t utf-8 | base64 But it is giving error iconv: (stdin):1:10: cannot convert `locale` outputs: ``` LANG= LC_CTYPE="C.UTF-8" LC_NUMERIC="C.UTF-8" LC_TIME="C.UTF-8" LC_COLLATE="C.UTF-8" LC_MONETARY="C...
I am trying to base64 encode a string which contains accent characters.
echo FILE_DATE.Ç | iconv -t utf-8 | base64
But it is giving error
iconv: (stdin):1:10: cannot convert
locale
outputs:
LANG=
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_ALL=
Umesh Kumar
(101 rep)
May 16, 2024, 08:30 AM
• Last activity: May 18, 2024, 08:28 AM
2
votes
2
answers
1407
views
I used to not need "-i" when using base64
I am using macOs 13.6.1 (22G313) for a machine. I used to be able to `base64` a .p12 file (maybe 1 - 3 years ago) using the following format from the terminal: base64 mastercard-track.p12 > mastercard-track_base64.txt Now when I attempt to use the `base64` program like that, I get this error: base64...
I am using macOs 13.6.1 (22G313) for a machine.
I used to be able to
base64
a .p12 file (maybe 1 - 3 years ago) using the following format from the terminal:
base64 mastercard-track.p12 > mastercard-track_base64.txt
Now when I attempt to use the base64
program like that, I get this error:
base64: invalid argument mastercard-track.p12
Usage: base64 [-hDd] [-b num] [-i in_file] [-o out_file]
-h, --help display this message
-Dd, --decode decodes input
-b, --break break encoded string into num character lines
-i, --input input file (default: "-" for stdin)
-o, --output output file (default: "-" for stdout)
Is the base64
program I used to use different now?
Zack Macomber
(131 rep)
Jan 18, 2024, 05:41 PM
• Last activity: Jan 19, 2024, 02:41 PM
4
votes
1
answers
3543
views
Javascript BTOA vs base64 in bash?
I need to convert a username and password combination into base64 before sending to an API. The javascript BTOA function is working for me, but when I try to use base64 command in bash I get slightly different results. **Javascript:** btoa("hello"); # aGVsbG8= btoa("username:password"); # dXNlcm5hbW...
I need to convert a username and password combination into base64 before sending to an API.
The javascript BTOA function is working for me, but when I try to use base64 command in bash I get slightly different results.
**Javascript:**
btoa("hello"); # aGVsbG8=
btoa("username:password"); # dXNlcm5hbWU6cGFzc3dvcmQ=
btoa("testing"); # dGVzdGluZw==
**Bash:**
echo hello | base64 # aGVsbG8K
echo username:password | base64 # dXNlcm5hbWU6cGFzc3dvcmQK
echo testing | base64 # dGVzdGluZwo=
Results are always similar but different.
Server expects the JS style encoding, but I need to use bash.
Why are the results different but similar? How can I produce the results from javascript with bash?
Philip Kirkbride
(10746 rep)
Aug 3, 2017, 02:40 PM
• Last activity: Dec 6, 2023, 06:52 PM
0
votes
1
answers
961
views
How to make base64 print the encoded output after a newline without newline being encoded?
I like to encode with `base64` from stdin by invoking the command pasting the input and pressing Ctrl + D twice in order to avoid a trailing newline if I don't want one to be part of the input. It avoids `echo` and leaves no data in the shell history. However, the output is written directly after th...
I like to encode with
base64
from stdin by invoking the command pasting the input and pressing Ctrl + D twice in order to avoid a trailing newline if I don't want one to be part of the input. It avoids echo
and leaves no data in the shell history.
However, the output is written directly after the input and it's hard to retrieve the value:
$ base64
Input without trailing newlineSW5wdXQgd2l0aG91dCB0cmFpbGluZyBuZXdsaW5l
Is there any way I can look like
$ base64
Input without trailing newline
SW5wdXQgd2l0aG91dCB0cmFpbGluZyBuZXdsaW5l
without any newlines being included in the encoded output?
I'm using Ubuntu 23.10.
Kalle Richter
(2252 rep)
Nov 20, 2023, 11:24 AM
• Last activity: Nov 20, 2023, 11:38 AM
1
votes
1
answers
1361
views
How to decode base64-encoded inline attachments in email files saved from Thunderbird or Gmail?
Although `base64 [--decode]` works well when encoding and decoding files locally, I can't decode a base64-encoded inline attachment in an eml file saved from Thunderbird or Gmail. I observed that base64-encoded blocks in all eml files are similar to what `base64` generates, but lines are of differen...
Although
base64 [--decode]
works well when encoding and decoding files locally, I can't decode a base64-encoded inline attachment in an eml file saved from Thunderbird or Gmail.
I observed that base64-encoded blocks in all eml files are similar to what base64
generates, but lines are of different length: the lines in base64-encoded blocks of text in eml files consist of **72 characters**, while the locally generated base64-encoded files consist of **76-character-long** lines. I suspect this discrepancy is why I cannot successfully use base64 --decode
on snippets of eml files.
Is my hypothesis true? How can I decode these attachments?
Sadi
(515 rep)
Nov 15, 2023, 04:57 PM
• Last activity: Nov 18, 2023, 09:17 AM
0
votes
1
answers
19544
views
Can you search for base64 with grep?
Is it possible to search for Base64 strings with grep? Say I have a list of text files and I want to find all the Base64 strings contained in them; is there any way to search for them? I mean I know they usually end with `=` or `==` and they also have sequences of bytes which relate to what [letters...
Is it possible to search for Base64 strings with grep? Say I have a list of text files and I want to find all the Base64 strings contained in them; is there any way to search for them? I mean I know they usually end with
=
or ==
and they also have sequences of bytes which relate to what letters they are encoded as within the base64 string. But as for searching for them in general (without knowing anything about what is encoded) I don't really know how to do so.
leeand00
(4937 rep)
Sep 18, 2019, 12:37 PM
• Last activity: Nov 16, 2023, 11:04 AM
8
votes
1
answers
1101
views
Why is 0x00 being deleted when assigning a base64 decoded string to a variable
I'm using a Mac. In Bash, I'm trying to decode a base64 string and then try to print the Hex value. I'm using `base64 -d` command and then assigning it to a variable. ``` myText='YYN29+2wV2XRAHymIyhgytWuqY4atgHnIUFfXA7FPOA=' myTextBytes=$(echo -n "$myText" | base64 --decode) echo -n $myTextBytes | x...
I'm using a Mac. In Bash, I'm trying to decode a base64 string and then try to print the Hex value. I'm using
base64 -d
command and then assigning it to a variable.
myText='YYN29+2wV2XRAHymIyhgytWuqY4atgHnIUFfXA7FPOA='
myTextBytes=$(echo -n "$myText" | base64 --decode)
echo -n $myTextBytes | xxd -p -c 99999
The output of the above script is:
> 618376f7edb05765d17ca6232860cad5aea98e1ab601e721415f5c0ec53ce0
However, if i were to run the following command directly:
echo -n "$myText" | base64 --decode | xxd -p -c 100000
I get:
> 618376f7edb05765d1**00**7ca6232860cad5aea98e1ab601e721415f5c0ec53ce0
I even tried using openssl enc -base64
and I get the same result. That is, 00
is getting deleted when assigning to a variable. How do I preserve the 00
when I'm assigning it to a variable?
SilleBille
(191 rep)
Aug 25, 2023, 11:11 PM
• Last activity: Aug 30, 2023, 09:12 PM
0
votes
0
answers
79
views
Google Cloud does not like my Customer-supplied encryption key (CSEK)
I'm trying to encrypt a VM image with my own provided key. [![enter image description here][1]][1] So I go to my Terminal emulator and do: ``` $ openssl enc -aes256 -A -P enter aes-256-cbc encryption password: Verifying - enter aes-256-cbc encryption password: salt=DCD571B7A0EC122B key=786D832EBF415...
I'm trying to encrypt a VM image with my own provided key.
So I go to my Terminal emulator and do:
So I read the documentation from Google about CSEK and it reads:
So I run that script, I get the results in base64, but then it doesn't accept it (however, it does accept the one from the Google example).
Do I have to pass this resulting base64 string to

$ openssl enc -aes256 -A -P
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
salt=DCD571B7A0EC122B
key=786D832EBF415B5F6BCF852AC8DC38826D904DEAFC53885F3B9F49003788B073
iv =B641A744631C462ED2896563F2AB9A1C
I punch in the key into Google cloud and it throws back an error:


openssl enc
?
I'm a bit lost, and Google doesn't provide any results that apply to my case.
Any help and/or guidance would be greatly appreciated!
mariano-daniel
(227 rep)
Jun 11, 2023, 01:18 AM
• Last activity: Jun 11, 2023, 12:31 PM
0
votes
2
answers
515
views
Replace a base64 value from file
I have one file which is gets details from ldapsearch command and create file as below # lschuler, people, pl.s2-eu.XXXXXXXXX.local dn: uid=lschuler,ou=people,dc=pl,dc=s2-eu,dc=XXXXXXXXX,dc=local objectClass: posixAccount objectClass: inetOrgPerson objectClass: organizationalPerson objectClass: pers...
I have one file which is gets details from ldapsearch command and create file as below
# lschuler, people, pl.s2-eu.XXXXXXXXX.local
dn: uid=lschuler,ou=people,dc=pl,dc=s2-eu,dc=XXXXXXXXX,dc=local
objectClass: posixAccount
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
loginShell: /bin/bash
homeDirectory: /home/lschuler
gidNumber: 10000
uid: lschuler
cn: Leonie Schuessler
uidNumber: 20056
mail: XXXXXXXX@XXXXXXXXX.com
sn: Schuessler
givenName: Leonie
# cadelie, people, pl.s2-eu.XXXXXXXXX.local
dn: uid=cadelie,ou=people,dc=pl,dc=s2-eu,dc=XXXXXXXXX,dc=local
objectClass: posixAccount
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
loginShell: /bin/bash
homeDirectory: /home/cadelie
gidNumber: 10000
uid: cadelie
cn:: Q2hsb8OpIEFkw6lsaWU=
uidNumber: 20057
mail: XXXXXXX@XXXXXXXXX.com
sn:: QWTDqWxpZQ==
givenName:: Q2hsb8Op
if you see **sn::** & **givenName::** some times have base64 value I want to decode it with command which I am not able to do
cat file.text | sed -e "s/.*sn:: //g;s/;.*//" |base64 -d && cat file.text | sed -e "s/.*givenName:: //g;s/;.*//" |base64 -d
how I can decode only sn:: & givenName:: which has base64 value and save to same file again.
Please help,
SAMURAI
Samurai
(95 rep)
Feb 17, 2023, 12:24 PM
• Last activity: Feb 20, 2023, 12:31 PM
0
votes
1
answers
1682
views
Trying to decode base64 from curl, but I get "base64: invalid input"
Trying to decode base64 from curl, but I get "base64: invalid input". ```console ➜ curl -s 'preprod-payroll.trick.htb/index.php?page=php://filter/convert.base64-encode/resource=home' | grep -A 1 ' ' | grep -v main PD9waHAgaW5jbHVkZSAnZGJfY29ubmVjdC5waHAnID8+DQo8c3R5bGU+DQogICANCjwvc3R5bGU+DQoNCjxkaX...
Trying to decode base64 from curl, but I get "base64: invalid input".
➜ curl -s 'preprod-payroll.trick.htb/index.php?page=php://filter/convert.base64-encode/resource=home' | grep -A 1 '' | grep -v main
PD9waHAgaW5jbHVkZSAnZGJfY29ubmVjdC5waHAnID8+DQo8c3R5bGU+DQogICANCjwvc3R5bGU+DQoNCjxkaXYgY2xhc3M9ImNvbnRhaW5lLWZsdWlkIj4NCg0KCTxkaXYgY2xhc3M9InJvdyI+DQoJCTxkaXYgY2xhc3M9ImNvbC1sZy0xMiI+DQoJCQkNCgkJPC9kaXY+DQoJPC9kaXY+DQoNCgk8ZGl2IGNsYXNzPSJyb3cgbXQtMyBtbC0zIG1yLTMiPg0KCQkJPGRpdiBjbGFzcz0iY29sLWxnLTEyIj4NCiAgICAgICAgICAgICAgICA8ZGl2IGNsYXNzPSJjYXJkIj4NCiAgICAgICAgICAgICAgICAgICAgPGRpdiBjbGFzcz0iY2FyZC1ib2R5Ij4NCiAgICAgICAgICAgICAgICAgICAgPD9waHAgZWNobyAiV2VsY29tZSBiYWNrICIuICRfU0VTU0lPTlsnbG9naW5fbmFtZSddLiIhIiAgPz4NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICANCiAgICAgICAgICAgICAgICAgICAgPC9kaXY+DQogICAgICAgICAgICAgICAgICAgIA0KICAgICAgICAgICAgICAgIDwvZGl2Pg0KICAgICAgICAgICAgPC9kaXY+DQoJPC9kaXY+DQoNCjwvZGl2Pg0KPHNjcmlwdD4NCgkNCjwvc2NyaXB0Pg==
➜ curl -s 'preprod-payroll.trick.htb/index.php?page=php://filter/convert.base64-encode/resource=home' | grep -A 1 '' | grep -v main | base64 -d
base64: invalid input
I can decode using base64 separately.
➜ echo 'PD9waHAgaW5jbHVkZSAnZGJfY29ubmVjdC5waHAnID8+DQo8c3R5bGU+DQogICANCjwvc3R5bGU+DQoNCjxkaXYgY2xhc3M9ImNvbnRhaW5lLWZsdWlkIj4NCg0KCTxkaXYgY2xhc3M9InJvdyI+DQoJCTxkaXYgY2xhc3M9ImNvbC1sZy0xMiI+DQoJCQkNCgkJPC9kaXY+DQoJPC9kaXY+DQoNCgk8ZGl2IGNsYXNzPSJyb3cgbXQtMyBtbC0zIG1yLTMiPg0KCQkJPGRpdiBjbGFzcz0iY29sLWxnLTEyIj4NCiAgICAgICAgICAgICAgICA8ZGl2IGNsYXNzPSJjYXJkIj4NCiAgICAgICAgICAgICAgICAgICAgPGRpdiBjbGFzcz0iY2FyZC1ib2R5Ij4NCiAgICAgICAgICAgICAgICAgICAgPD9waHAgZWNobyAiV2VsY29tZSBiYWNrICIuICRfU0VTU0lPTlsnbG9naW5fbmFtZSddLiIhIiAgPz4NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICANCiAgICAgICAgICAgICAgICAgICAgPC9kaXY+DQogICAgICAgICAgICAgICAgICAgIA0KICAgICAgICAgICAgICAgIDwvZGl2Pg0KICAgICAgICAgICAgPC9kaXY+DQoJPC9kaXY+DQoNCjwvZGl2Pg0KPHNjcmlwdD4NCgkNCjwvc2NyaXB0Pg==' | base64 -d
Can anyone please help me.
R4J
(1 rep)
Nov 4, 2022, 10:55 AM
• Last activity: Nov 4, 2022, 11:03 AM
3
votes
1
answers
3651
views
How to decode base64 for both Linux and macOS?
On Linux I can do: ```bash echo ${ANDROID_KEYSTORE} | base64 -di > android/keystores/staging.keystore ``` But on macOS, the same commands give: ```bash base64: option requires an argument -- i Usage: base64 [-hvDd] [-b num] [-i in_file] [-o out_file] -h, --help display this message -Dd, --decode dec...
On Linux I can do:
echo ${ANDROID_KEYSTORE} | base64 -di > android/keystores/staging.keystore
But on macOS, the same commands give:
base64: option requires an argument -- i
Usage: base64 [-hvDd] [-b num] [-i in_file] [-o out_file]
-h, --help display this message
-Dd, --decode decodes input
-b, --break break encoded string into num character lines
-i, --input input file (default: "-" for stdin)
-o, --output output file (default: "-" for stdout)
I have tried to replace -di
with --decode --input
, but it didn't help.
1. How do I fix the macOS command?
2. Is there a command that works both on Linux (Debian/Ubuntu) and macOS?
Dimitri Kopriwa
(143 rep)
Oct 31, 2022, 05:10 PM
• Last activity: Nov 1, 2022, 07:30 AM
0
votes
1
answers
772
views
How to force base64 encoding for s-nail attachments?
I have a job that picks up CSV files and sends them through an external mail service. Everything seems to be great, with one exception: I found that the windows style CRLF CSV files get mangled by the process and when I open them in a mail client, they have 3 0x0A characters at the end of each line....
I have a job that picks up CSV files and sends them through an external mail service. Everything seems to be great, with one exception: I found that the windows style CRLF CSV files get mangled by the process and when I open them in a mail client, they have 3 0x0A characters at the end of each line.
I thought it would be easy to force base64 encoding of the files, but though it feels like s-nail should be a Ferrari from a programmability perspective, I can't find the gas pedal. Playing around with the mime settings, I can change the content type, but getting the payload to base 64 is just not happening.
echo "CSV files attached:" | s-nail -vv -Smimetypes-load-control -X'mimetype "application/octet-stream csv"' -r noreply@example.com -s "Your CSV file" -a /data/review/fun.csv -S smtp-use-starttls -S smtp-auth=login -S smtp-auth-user="butts@corgibutts.com" -S smtp-auth-password="yourmom" -S smtp="corgibutts.com:587" "user@example.com"
Does anyone have any idea how to make this happen?
lopass
(79 rep)
Sep 28, 2022, 08:54 PM
• Last activity: Oct 5, 2022, 03:32 PM
0
votes
0
answers
556
views
base64 decode as save as multiple files
I have a file(har file saved from web developer" that contains the base64 encoded value of multiple video*.ts files. I am interested to decode the base64 part and save as multiple ts files if the request url is a .ts file and the response encoding should be base64. "request": { "bodySize": 0, "metho...
I have a file(har file saved from web developer" that contains the base64 encoded value of multiple video*.ts files. I am interested to decode the base64 part and save as multiple ts files if the request url is a .ts file and the response encoding should be base64.
"request": {
"bodySize": 0,
"method": "GET",
"url": "https://vz-73062248-092.b-cdn.net/856d96e6-97e6-4c3d-82b8-a53a8a411513/1920x1080/video1.ts ",
......
.....
....
"response":{
.....
.....
"content": {
"mimeType": "video/mp2t",
"size": 882472,
"encoding": "base64",
"text": "R................=="}, ----->should be decoded from this string as video1.ts
.....
The above should be saved as video1.ts , decoded from the base64 string between "text": ", till "
There are multiple entries for the ts files from 1 till 350 in the file. The file is around 500MB
Please please let me know hoe can i save as multiple ts files from the base64 decoded string from the file?
maneesh murali
(101 rep)
Jul 19, 2022, 07:00 PM
0
votes
3
answers
320
views
Replace a timestamp Base64 value in a file
I have a problem, I have a file test.txt that has a content like this: dn: serv=CSPS,mscId=167e48dc2b7a42d4acce611c8b477262,ou=multiSCs,dc=three structuralObjectClass: CP1 objectClass: CP1 objectClass: CUDBServiceAuxiliary objectClass: CP2 objectClass: CP3 objectClass: CP4 objectClass: CP5 objectCla...
I have a problem, I have a file test.txt that has a content like this:
dn: serv=CSPS,mscId=167e48dc2b7a42d4acce611c8b477262,ou=multiSCs,dc=three
structuralObjectClass: CP1
objectClass: CP1
objectClass: CUDBServiceAuxiliary
objectClass: CP2
objectClass: CP3
objectClass: CP4
objectClass: CP5
objectClass: CP6
UNKNLOCDATECS:: FQsJ
UNKNLOCDATEPS:: FgMe
ISTTIMESTAMP:: FgMIDyI7
CSULTIME:: HgMWCzYo
CSLOCTIME:: AQQWBA0R
PSULTIME:: HgMWDBco
PSLOCTIME:: HgMWDBco
SCHAR:: AgA=
ICS: 1
CAT: 10
DBSG: 1
OFA: 1
SOCB: 1
PWD: 0000
PWDC: 0
SOCFB: 0
Every time the text CSULTIME:: and CSLOCTIME:: are found I want to replace the value after those literals with the following funtion to decode that timestamp to a recognize format (if I can replace both values in a single scan of the file better as we are talking about 8 GB file and the function is the same in both cases):
base64 -d | hexdump -v -e '1/1 "%02d" ' | awk 'BEGIN {FS = ""} {print "20" $5 $6 "-" $3 $4 "-" $1 $2 " " $7 $8 ":" $9 $10 ":" $11 $12}'
If I do in unix an echo for those two values:
For CSULTIME the result would be 2022-03-30 11:54:40: echo -n "HgMWCzYo" | base64 -d | hexdump -v -e '1/1 "%02d" ' | awk 'BEGIN {FS = ""} {print "20" $5 $6 "-" $3 $4 "-" $1 $2 " " $7 $8 ":" $9 $10 ":" $11 $12}'
For CSLOCTIME the result would be 2022-04-01 04:13:17: echo -n "AQQWBA0R" | base64 -d | hexdump -v -e '1/1 "%02d" ' | awk 'BEGIN {FS = ""} {print "20" $5 $6 "-" $3 $4 "-" $1 $2 " " $7 $8 ":" $9 $10 ":" $11 $12}'
So at the end the file would have these values for CSULTIME and CSLOCTIME:
dn: serv=CSPS,mscId=167e48dc2b7a42d4acce611c8b477262,ou=multiSCs,dc=three
structuralObjectClass: CP1
objectClass: CP1
objectClass: CUDBServiceAuxiliary
objectClass: CP2
objectClass: CP3
objectClass: CP4
objectClass: CP5
objectClass: CP6
UNKNLOCDATECS:: FQsJ
UNKNLOCDATEPS:: FgMe
ISTTIMESTAMP:: FgMIDyI7
CSULTIME:: 2022-03-30 11:54:40
CSLOCTIME:: 2022-04-01 04:13:17
PSULTIME:: HgMWDBco
PSLOCTIME:: HgMWDBco
SCHAR:: AgA=
ICS: 1
CAT: 10
DBSG: 1
OFA: 1
SOCB: 1
PWD: 0000
PWDC: 0
SOCFB: 0
I'm completely lost as all combinations I'm trying of sed I can't make them work.
Thanks in advance!!!!
Sergio Jimenez
(79 rep)
Apr 28, 2022, 02:17 PM
• Last activity: May 2, 2022, 05:35 AM
-1
votes
1
answers
14243
views
base64: invalid input error when trying to decode contents of yaml file
>**What specific syntax must be changed in the bash below to successfully decode the base64 encoded value which is throwing the error below?** **THE ERROR:** The following 3 simple commands are typed into the terminal of a RHEL 8 vm running in Azure: [user@myVM ~]$ myVar=$(az keyvault secret show --...
>**What specific syntax must be changed in the bash below to successfully decode the base64 encoded value which is throwing the error below?**
**THE ERROR:**
The following 3 simple commands are typed into the terminal of a RHEL 8 vm running in Azure:
[user@myVM ~]$ myVar=$(az keyvault secret show --name "secretName" --vault-name "vaultName" --query "value")
[user@myVM ~]$ echo $myVar
"very.long.base64.encoded.string.representing.the.original.yaml"
[user@myVM ~]$ echo $myVar | base64 --decode
base64: invalid input
The second command prints what looks like valid base64 encoding of a long string, perhaps a few hundred characters or more encoded.
The error
base64: invalid input
seems to indicate that the base64
program is not able to accept the encoded input into its decode command.
**THE SOURCE DATA:**
The contents of the base64 encoded data above originated in a yaml file with perhaps 20 lines, which was passed through [terraform's fileBase64()
command](https://www.terraform.io/language/functions/filebase64) as follows before the VM was created:
resource "azurerm_key_vault_secret" "secretName" {
name = "secretName"
value = filebase64(var.keySourceFile)
key_vault_id = azurerm_key_vault.vaultName.id
}
**RESULTS OF TRYING USER SUGGESTIONS:**
Per @roaima suggestion, we tried the following:
[user@myVM ~]$ az keyvault secret show --name "secretName" --vault-name "vaultName" --query "value"
"very.long.base64.encoded.string.representing.the.original.yaml=="
[user@myVM ~]$ myVar=$(az keyvault secret show --name "secretName" --vault-name "vaultName" --query "value")
[user@myVM ~]$ echo "$myVar" | base64 --decode >/dev/null
base64: invalid input
As you can see, we validated that a long encoded string is presented by the raw command before we put it into myVar
. Note that it ends with ==
and is surrounded by double-quotes.
The raw data in the original source file that was sent into terraform looks something like:
secret1: value1
secret2: value2
...
secretN: valueN
Then we tried the following but you can see nothing was returned:
[user@myVM ~]$ printf '%s\n' "$myVar" | base64 --decode --ignore-garbage >/dev/null
[user@myVM ~]$
CodeMed
(5357 rep)
Apr 14, 2022, 09:52 PM
• Last activity: Apr 15, 2022, 07:34 AM
Showing page 1 of 20 total questions