Why is command line computed base64 string differe

2019-05-06 22:54发布

Really confused - Guess it has to do with a single character placement at the end, or possible padding done with basic digest that I'm not aware of..?

So, if I execute this, you can see the product of the base64 encode:

echo 'host@mail.com:password' | openssl enc -base64
aG9zdEBtYWlsLmNvbTpwYXNzd29yZAo=

Now, if I make a curl request:

curl -v -u host@mail.com:password https://
aG9zdEBtYWlsLmNvbTpwYXNzd29yZA==

You'll notice that the base64 strings are NOT the same..haha what? The base64 command line one is actually incorrect - if you substitute that in the request, it fails. SO - does basic digest NOT truly use a base64 string? I'm noticing that is always doing a o= instead of == at the end of the string ...

And ideas?

EDIT: So, it was the trailing newline from echo: -n do not output the trailing newline

Thanks!

1条回答
ら.Afraid
2楼-- · 2019-05-06 23:48
>>> 'aG9zdEBtYWlsLmNvbTpwYXNzd29yZA=='.decode('base64')
'host@mail.com:password'
>>> 'aG9zdEBtYWlsLmNvbTpwYXNzd29yZAo='.decode('base64')
'host@mail.com:password\n'

Try echo -n instead.

查看更多
登录 后发表回答