获取密码的base64版本 [英] Get base64 version of password
问题描述
我有以下命令:
echo -n "cdt_main!@#$" | base64
失败:
bash: !@#$": event not found
lulz b/c特殊字符.所以我最好的猜测是这是正确的:
lulz b/c of the special characters. So my best guess is that this is correct:
echo -n "cdt_main\!\@#\$" | base64
至少这是b/c,现在没有错误.不幸的是,直到我知道它是正确的,我才能测试base64版本的密码-我只有一次机会将它正确设置,否则会炸毁某些东西.您觉得合适吗?
at least this is b/c there is no error now. Unfortunately I cannot test the base64 version password until I know that it's right - I have only one chance to get it right o/w something will blow up. Does that look right to you?
使用解码技巧,我有:
echo -n "cdt_main\!\@#\$" | base64 | base64 --decode
产生:
cdt_main\!\@#$
给出该输出,不确定其中是否按计划工作,因为其中存在斜杠.
given that output, not sure if this is working as planned, because slashes are in there.
推荐答案
问题是bash的历史记录扩展已打开.除非您要积极地使用历史扩展功能,否则解决方案是将其关闭.
The problem is that bash's history expansion is turned on. Unless you history expansion is something that you actively want and use, the solution is to turn it off.
发现此操作失败,并没有找到 event
:
Observe that this fails with event not found
:
$ echo -n "cdt_main!@#$" | base64
bash: !@#: event not found
但是,这成功了:
$ set +H
$ echo -n "cdt_main!@#$" | base64
Y2R0X21haW4hQCMk
set + H
关闭历史记录扩展.
对于双引号内的字符串,shell将执行各种各样的扩展.为了防止这种情况,请在字符串中使用单引号引起来.
For strings inside double quotes, the shell will perform a wide variety of expansions. To prevent that, put strings instead in single quotes.
例如,即使打开历史记录扩展,以下操作也会成功:
For example, the following succeeds even with history expansion turned on:
$ set -H
$ echo -n 'cdt_main!@#$' | base64
Y2R0X21haW4hQCMk
便携式方法
并非所有外壳程序都支持 echo
的 -n
选项.对于更便携的解决方案,应按照 Gordon Davisson 的建议,使用 printf
:
Portable approach
The -n
option to echo
is not supported by all shells. For a more portable solution, one should, as Gordon Davisson suggests, use printf
:
printf "%s" 'cdt_main!@#$' | base64
这篇关于获取密码的base64版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!