有些代码规范要求源代码/配置文件/脚本文件等项目文件中不得出现明文密码,无论这个是数据库密码、服务器密码还是其他的,有时候甚至是用户名也得配置成密文。
对于部署在Linux x86服务器上面的应用文件,这里提供了最简单粗暴、也算是最初级的解决方案,借助Linux的base64命令,调用操作系统命令即可进行加密/解密操作。
NAME
base64 - base64 encode/decode data and print to standard output
SYNOPSIS
base64 [OPTION]... [FILE]
DESCRIPTION
Base64 encode or decode FILE, or standard input, to standard output.
Mandatory arguments to long options are mandatory for short options too.
-d, --decode
decode data
-i, --ignore-garbage
when decoding, ignore non-alphabet characters
-w, --wrap=COLS
wrap encoded lines after COLS character (default 76). Use 0 to disable line wrapping
--help display this help and exit
--version
output version information and exit
复制
加密操作示例:
[root@test ~]# echo 'hello_world!' | base64 -i
aGVsbG9fd29ybGQhCg==
[root@test ~]# echo 'hello_world!' | base64
aGVsbG9fd29ybGQhCg==
复制
解密操作示例:
[root@test ~]# echo 'aGVsbG9fd29ybGQhCg==' | base64 -d
hello_world!
复制
文章转载自IT技术佳肴,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。