使用 Base64 编码密码时是否需要包含 -n 选项?
我在某个地方读到,在基本64中编码密码时,我应该使用echo -n
来防止新线包含在编码值中。例如,
echo changeme | base64
Y2hhbmdlbWUK
echo -n changeme | base64
Y2hhbmdlbWU=
这两个base64字符串是不同的,但是当我解码它们时,它们是相同的
echo Y2hhbmdlbWUK | base64 -d
changeme
echo Y2hhbmdlbWU= | base64 -d
changeme
,所以我真的需要添加-n
option https://linux.die.net/男人/1/echo
说:
请勿输出尾线
搜索,并使用Python为这个长期的示例提供了根据密码编码字符串的简单方法?
I read somewhere that when encoding a password in base64, I should use echo -n
to prevent the newline from being included in the encoded value. For example,
echo changeme | base64
Y2hhbmdlbWUK
echo -n changeme | base64
Y2hhbmdlbWU=
These two base64 strings are different, but when I decode them they are the same
echo Y2hhbmdlbWUK | base64 -d
changeme
echo Y2hhbmdlbWU= | base64 -d
changeme
So do I really need to add the -n
option https://linux.die.net/man/1/echo
says:
do not output the trailing newline
Searches gave this long winded example using python... didn't read it all Simple way to encode a string according to a password?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用 在线转换器 将其解码为十六进制时,您会看到第一个字符串变为
6368616e67656d650a
并在末尾有0a
(ASCII 换行符),而第二个则没有。所以答案是肯定的,您确实需要添加 -n 选项。
如果您将
echo
更改为echo -n
您会看到这也是。查看此情况的另一种方法是使用以下 UNIX 命令:
您可以在其中看到第一个编码包含换行符,而第二个则不包含换行符。
When you use an online converter to decode it to hex, you'll see that the first string becomes
6368616e67656d650a
and has0a
(ASCII Linefeed) on the end, which the second doesn't have.So the answer is yes, you really need to add the -n option.
If you change your
echo
toecho -n
you'll see this as well.Another way to see this is using the following UNIX command:
Where you can see the first encoding includes the linefeed and the second does not.