17

I am using the java based neo4j graph database on lubuntu 15.04.

The neo4j HTTP authentication header uses base64 encoding of 'username:password' (not including quotes). Using wireshark I can see the base64 code generated by neo4j.

However if I use the ubuntu coreutils base64 to encode the same string I get a slightly different encoding. This encoding is not accepted by neo4j.

Both encodings decode to the correct username:password string

Example

username=neo4j and password=@N

Neo4j gives the encoded value of neo4j:@N as bmVvNGo6QE4= which decodes to neo4j:@N as expected

$ echo 'bmVvNGo6QE4=' | base64 --decode
neo4j:@N

Ubuntu coreutils base64 returns the encoded value of neo4j:@N as bmVvNGo6QE4K (which differs in the last character) but still decodes correctly;

$ echo 'neo4j:@N' | base64
bmVvNGo6QE4K
$ echo 'bmVvNGo6QE4K' | base64 --decode
neo4j:@N

Why is this? What do I need to do get consistent encoding?

muru
  • 193,181
  • 53
  • 473
  • 722
Lozdown
  • 173
  • 1
  • 6
  • 3
    Note that `=` in normal Base64 is **padding** (and only valid at the end). The fact that one encoded string has padding and the other does not (or more generally, that the two strings have different amounts of padding) is a dead giveaway that the two are of **different length** and thus cannot possibly be identical. – user Oct 01 '15 at 07:29

1 Answers1

67

You are encoding (slightly) different strings:

$ echo 'bmVvNGo6QE4=' | base64 --decode | od -c
0000000   n   e   o   4   j   :   @   N
0000010
$ echo 'neo4j:@N' | od -c
0000000   n   e   o   4   j   :   @   N  \n
0000011

echo adds a trailing newline character. This leads to differing encodings.

Use printf instead, whose output specification is more exact:

$ printf '%s' 'neo4j:@N' | base64              
bmVvNGo6QE4=
muru
  • 193,181
  • 53
  • 473
  • 722