有些代码规范要求源代码/配置文件/脚本文件等项目文件中不得出现明文密码,无论这个是数据库密码、服务器密码还是其他的,有时候甚至是用户名也得配置成密文。

对于部署在Linux x86服务器上面的应用文件,这里提供了最简单粗暴、也算是最初级的解决方案,借助Linux的base64命令,调用操作系统命令即可进行加密/解密操作。
NAMEbase64 - base64 encode/decode data and print to standard outputSYNOPSISbase64 [OPTION]... [FILE]DESCRIPTIONBase64 encode or decode FILE, or standard input, to standard output.Mandatory arguments to long options are mandatory for short options too.-d, --decodedecode data-i, --ignore-garbagewhen decoding, ignore non-alphabet characters-w, --wrap=COLSwrap encoded lines after COLS character (default 76). Use 0 to disable line wrapping--help display this help and exit--versionoutput version information and exit
加密操作示例:
[root@test ~]# echo 'hello_world!' | base64 -iaGVsbG9fd29ybGQhCg==[root@test ~]# echo 'hello_world!' | base64aGVsbG9fd29ybGQhCg==
解密操作示例:
[root@test ~]# echo 'aGVsbG9fd29ybGQhCg==' | base64 -dhello_world!

文章转载自IT技术佳肴,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




