开发者

Why is command line computed base64 string different than curl computed base64 string?

开发者 https://www.devze.com 2022-12-17 02:25 出处:网络
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..?

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 开发者_如何学C== 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!


>>> 'aG9zdEBtYWlsLmNvbTpwYXNzd29yZA=='.decode('base64')
'host@mail.com:password'
>>> 'aG9zdEBtYWlsLmNvbTpwYXNzd29yZAo='.decode('base64')
'host@mail.com:password\n'

Try echo -n instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号