LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   A question about generating base64 strings... (https://www.linuxquestions.org/questions/linux-newbie-8/a-question-about-generating-base64-strings-868943/)

trist007 03-16-2011 10:00 AM

A question about generating base64 strings...
 
I've been messing around with smtp auth plain authentication. I've been using the following command to generate the auth plain base64 hash.
Code:

perl -MMIME::Base64 -e 'print encode_base64("\000username\@domain.com\000password")'
And that hash has been working great. However, I wanted to use something a little easier to remember. So I tried the following.
Code:

echo -n "\000username\@domain.com\000password" | base64
but the resulting hash is different. I can't seem to figure it out. What do the '\000' represent?

ntubski 03-16-2011 10:26 AM

Quote:

What do the '\000' represent?
They represent 0 (or NUL) bytes, which are distinct from bytes representing the character "0" (that would be 48 or 0x30). You have to pass the -e option to echo so interprets the escape sequence.

Quote:

auth plain base64 hash
Just to be clear, base64 encoding isn't a hash.

trist007 03-16-2011 01:21 PM

Ah got it. I needed to just have the nulls in quotes. So this worked.
Code:

echo -ne "\000"username\@domain.com"\000"password | base64
You need the '-n' so that newlines will not be printed. You need the '-e' so that the escapes will be accounted for.
Thanks ntubski for pointing me in the right direction.


All times are GMT -5. The time now is 03:56 AM.