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

心不动则不痛 提交于 2019-12-07 10:45:36

问题


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:


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

Try echo -n instead.



来源:https://stackoverflow.com/questions/2122105/why-is-command-line-computed-base64-string-different-than-curl-computed-base64-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!