Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-16-2011, 11:00 AM   #1
Senior Member
Registered: May 2008
Distribution: Slackware
Posts: 1,033

Rep: Reputation: 69
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.
perl -MMIME::Base64 -e 'print encode_base64("\000username\\000password")'
And that hash has been working great. However, I wanted to use something a little easier to remember. So I tried the following.
echo -n "\000username\\000password" | base64
but the resulting hash is different. I can't seem to figure it out. What do the '\000' represent?
Old 03-16-2011, 11:26 AM   #2
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,239

Rep: Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405
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.

auth plain base64 hash
Just to be clear, base64 encoding isn't a hash.
Old 03-16-2011, 02:21 PM   #3
Senior Member
Registered: May 2008
Distribution: Slackware
Posts: 1,033

Original Poster
Rep: Reputation: 69
Ah got it. I needed to just have the nulls in quotes. So this worked.
echo -ne "\000"username\"\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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] A innocent question about generating CSV file with php koshihaku Linux - Server 2 08-24-2010 09:47 PM
Using ; in command strings question. Thaidog Linux - General 2 04-21-2007 08:01 PM
Statistics and Programming Question, generating a random number firefly2442 Programming 2 01-06-2006 05:33 PM
strings question sibtay Programming 7 10-01-2004 11:37 AM
Help with a script (question on strings) wswartz Linux - General 3 07-11-2004 09:53 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:12 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration