简体   繁体   English

为什么命令行计算base64字符串不同于curl计算的base64字符串?

[英]Why is command line computed base64 string different than curl computed base64 string?

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: 所以,如果我执行它,你可以看到base64编码的产品:

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? 你会注意到base64字符串不一样......哈哈是什么? The base64 command line one is actually incorrect - if you substitute that in the request, it fails. base64命令行1实际上是不正确的 - 如果在请求中替换它,它将失败。 SO - does basic digest NOT truly use a base64 string? SO - 基本消化不真正使用base64字符串吗? I'm noticing that is always doing ao= instead of == at the end of the string ... 我注意到在字符串末尾总是做ao =而不是==

And ideas? 和想法?

EDIT: So, it was the trailing newline from echo: -n do not output the trailing newline 编辑:所以,它是echo的尾随换行符:-n不输出尾随换行符

Thanks! 谢谢!

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

Try echo -n instead. 请尝试使用echo -n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM